Skip to content

Commit

Permalink
Use --enable-preview for jdk19+ and replace deprecated -d option with…
Browse files Browse the repository at this point in the history
… --output
  • Loading branch information
krakowski committed Aug 4, 2022
1 parent 5d145ec commit baaaa15
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Since the plugin is available on [Gradle's Plugin Portal](https://plugins.gradle

```gradle
plugins {
id "io.github.krakowski.jextract" version "0.2.7"
id "io.github.krakowski.jextract" version "0.3.0"
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "io.github.krakowski"
version = "0.2.7"
version = "0.3.0"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
rootProject.name = "gradle-jextract"
rootProject.name = "gradle-jextract"
11 changes: 5 additions & 6 deletions src/main/kotlin/io/github/krakowski/jextract/JextractPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,17 @@ class JextractPlugin : Plugin<Project> {
}
}

// We need to add the foreign module, so the compiler sees its classes and
// We need to enable the preview mode, so the compiler sees jdk.lang.foreign classes and
// the java compiler should only be invoked after jextract generated its source files
target.tasks.withType<JavaCompile> {
dependsOn(jextractTask)
options.compilerArgs.add("--add-modules")
options.compilerArgs.add("jdk.incubator.foreign")
options.compilerArgs.add("--enable-preview")
}

target.tasks.withType<Test> {
jvmArgs = listOf(
"--enable-native-access=ALL-UNNAMED",
"--add-modules", "jdk.incubator.foreign"
"--enable-preview"
)
}
}
Expand All @@ -88,10 +87,10 @@ class JextractPlugin : Plugin<Project> {

val extension = target.extensions.getByType<JavaApplication>()

// We need to add the foreign module, so that the classes are visible at runtime
// We need to enable the preview mode, so that the jdk.lang.foreign classes are visible at runtime
extension.applicationDefaultJvmArgs += listOf(
"--enable-native-access=ALL-UNNAMED",
"--add-modules", "jdk.incubator.foreign"
"--enable-preview"
)
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/kotlin/io/github/krakowski/jextract/JextractTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,16 @@ abstract class JextractTask : DefaultTask() {
}

// Search for jextract in PATH if JDK has no bundled binary
val pathExecutable = System.getenv(ENV_PATH)
val envPath = System.getenv(ENV_PATH)
val pathExecutable = envPath
.split(File.pathSeparator)
.map { path -> Paths.get(path, executable) }
.filter { path -> Files.exists(path) }

try {
return pathExecutable.first()
} catch (exception: NoSuchElementException) {
throw GradleException("jextract binary could not be found in PATH or at ${bundledExecutable}")
throw GradleException("jextract binary could not be found in PATH or at ${bundledExecutable}\n\t↳ PATH=${envPath}")
}
}

Expand Down Expand Up @@ -160,7 +161,7 @@ abstract class JextractTask : DefaultTask() {
}

// Set output directory
arguments += "-d"
arguments += "--output"
arguments += outputDir.get().toString()

execute("${jextractBinary} ${arguments.joinToString(" ")} ${definition.header.get()}")
Expand Down

0 comments on commit baaaa15

Please sign in to comment.