Skip to content

Commit

Permalink
Build native-image on JDK 11+ (#8625)
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke authored Dec 24, 2024
1 parent fb22f49 commit 2281a4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
18 changes: 11 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ allprojects {
}
}

val platform = System.getProperty("okhttp.platform", "jdk9")
val testJavaVersion = System.getProperty("test.java.version", "21").toInt()

/** Configure building for Java+Kotlin projects. */
subprojects {
val project = this@subprojects
Expand Down Expand Up @@ -143,10 +146,14 @@ subprojects {
signature(rootProject.libs.codehaus.signature.java18) { artifact { type = "signature" } }
}

val javaVersionSetting = when (project.name) {
"okcurl", "native-image-tests" -> "11"
else -> "1.8"
}
val javaVersionSetting =
if (testJavaVersion > 8 && (project.name == "okcurl" || project.name == "native-image-tests")) {
// Depends on native-image-tools which is 11+, but avoids on Java 8 tests
"11"
} else {
"1.8"
}

val projectJvmTarget = JvmTarget.fromTarget(javaVersionSetting)
val projectJavaVersion = JavaVersion.toVersion(javaVersionSetting)

Expand All @@ -159,9 +166,6 @@ subprojects {
}
}

val platform = System.getProperty("okhttp.platform", "jdk9")
val testJavaVersion = System.getProperty("test.java.version", "21").toInt()

val testRuntimeOnly: Configuration by configurations.getting
dependencies {
testRuntimeOnly(rootProject.libs.junit.jupiter.engine)
Expand Down
20 changes: 13 additions & 7 deletions okcurl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.KotlinJvm
import org.apache.tools.ant.taskdefs.condition.Os
import org.graalvm.buildtools.gradle.dsl.GraalVMExtension

plugins {
kotlin("jvm")
id("org.jetbrains.dokka")
id("com.vanniktech.maven.publish.base")
id("org.graalvm.buildtools.native")
id("com.github.johnrengelman.shadow")
}

val testJavaVersion = System.getProperty("test.java.version", "21").toInt()

val copyResourcesTemplates = tasks.register<Copy>("copyResourcesTemplates") {
from("src/main/resources-templates")
into(layout.buildDirectory.dir("generated/resources-templates"))
Expand Down Expand Up @@ -53,11 +54,16 @@ tasks.shadowJar {
mergeServiceFiles()
}

graalvmNative {
binaries {
named("main") {
imageName = "okcurl"
mainClass = "okhttp3.curl.MainCommandLineKt"

if (testJavaVersion >= 11) {
apply(plugin = "org.graalvm.buildtools.native")

configure<GraalVMExtension> {
binaries {
named("main") {
imageName = "okcurl"
mainClass = "okhttp3.curl.MainCommandLineKt"
}
}
}
}
Expand Down

0 comments on commit 2281a4c

Please sign in to comment.