This is a Gradle plugin for integrating Project Panama's jextract
tool in the build process.
There is also a full demo project showcasing the gradle-jextract
plugin.
Since the plugin is available on Gradle's Plugin Portal it can be applied within the build script's plugins
block.
plugins {
id "io.github.krakowski.jextract" version "0.3.1"
}
Applying the plugin adds the jextract
task which can be configured by the build script.
jextract {
header("${project.projectDir}/src/main/c/stdio.h") {
// The library name
libraries = [ 'stdc++' ]
// The package under which all source files will be generated
targetPackage = 'org.unix'
// The generated class name
className = 'Linux'
}
}
If the Gradle Java Plugin or
Application plugin is applied, the gradle-jextract
plugin configures them and uses the configured toolchain for its task, which can be set as follows.
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(19))
}
}
If your JDK is not installed in one of the default locations, Gradle can be instructed to search in a custom location.
To enable this feature the org.gradle.java.installations.paths
property has to be set within your global gradle.properties
file usually located inside ${HOME}/.gradle
.
org.gradle.java.installations.paths=/custom/path/jdk19
The plugin will first try to find jextract
inside PATH
and then fall back to ${JAVA_HOME}/bin
.
The jextract
task exposes the following configuration options.
Name | Type | Required | Description |
---|---|---|---|
clangArguments |
java.lang.String |
Arguments which should be passed to clang | |
libraries |
java.lang.String[] |
The libraries against which the native code will link | |
includes |
java.lang.String[] |
A list of directories which should be included during code generation | |
targetPackage |
java.lang.String |
โซ | The package under which all bindings will be generated |
className |
java.lang.String |
The generated class file's name | |
functions |
java.lang.String[] |
Whitelist of function symbols | |
macros |
java.lang.String[] |
Whitelist of macro symbols | |
structs |
java.lang.String[] |
Whitelist of struct symbols | |
typedefs |
java.lang.String[] |
Whitelist of typedef symbols | |
unions |
java.lang.String[] |
Whitelist of union symbols | |
variables |
java.lang.String[] |
Whitelist of global variable symbols | |
definedMacros |
java.lang.String[] |
List of additional defined C preprocessor macros | |
sourceMode |
java.lang.Boolean |
Generate source files instead of class files (default: true ) |
|
outputDir |
org.gradle.api.file.Directory |
The output directory under which the generated source files will be placed |
This project is licensed under the GNU GPLv3 License - see the LICENSE file for details.