Skip to content

Commit fb22f49

Browse files
authored
Update to official GraalVM tooling (#8613)
1 parent 38bab5d commit fb22f49

File tree

27 files changed

+167
-635
lines changed

27 files changed

+167
-635
lines changed

.github/workflows/build.yml

+21-6
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,15 @@ jobs:
7878
distribution: 'zulu'
7979
java-version: 17
8080

81+
- uses: graalvm/setup-graalvm@v1
82+
with:
83+
distribution: 'graalvm'
84+
java-version: 21
85+
github-token: ${{ secrets.GITHUB_TOKEN }}
86+
cache: 'gradle'
87+
native-image-job-reports: true
88+
components: 'native-image'
89+
8190
- name: Setup Gradle
8291
uses: gradle/actions/setup-gradle@v4
8392

@@ -446,20 +455,26 @@ jobs:
446455
distribution: 'zulu'
447456
java-version: 17
448457

458+
- uses: graalvm/setup-graalvm@v1
459+
with:
460+
distribution: 'graalvm'
461+
java-version: 21
462+
github-token: ${{ secrets.GITHUB_TOKEN }}
463+
cache: 'gradle'
464+
native-image-job-reports: true
465+
components: 'native-image'
466+
449467
- name: Setup Gradle
450468
uses: gradle/actions/setup-gradle@v4
451469

452470
- name: Build okcurl
453-
run: ./gradlew okcurl:nativeImage
471+
run: ./gradlew okcurl:nativeBuild
454472

455473
- name: Setup Gradle
456474
uses: gradle/actions/setup-gradle@v4
457475

458-
- name: Build ConsoleLauncher
459-
run: ./gradlew -PgraalBuild=true native-image-tests:nativeImage
460-
461-
- name: Run Checks
462-
run: ./native-image-tests/build/graal/ConsoleLauncher
476+
- name: Run native-image tests
477+
run: ./gradlew -PgraalBuild=true native-image-tests:nativeTest
463478

464479
testandroid:
465480
runs-on: ubuntu-latest

build.gradle.kts

+11-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ buildscript {
1919
classpath(libs.gradlePlugin.kotlinSerialization)
2020
classpath(libs.gradlePlugin.androidJunit5)
2121
classpath(libs.gradlePlugin.android)
22-
classpath(libs.gradlePlugin.graal)
2322
classpath(libs.gradlePlugin.bnd)
2423
classpath(libs.gradlePlugin.shadow)
2524
classpath(libs.gradlePlugin.animalsniffer)
@@ -28,6 +27,7 @@ buildscript {
2827
classpath(libs.gradlePlugin.mavenPublish)
2928
classpath(libs.gradlePlugin.binaryCompatibilityValidator)
3029
classpath(libs.gradlePlugin.mavenSympathy)
30+
classpath(libs.gradlePlugin.graalvmBuildTools)
3131
}
3232

3333
repositories {
@@ -143,9 +143,16 @@ subprojects {
143143
signature(rootProject.libs.codehaus.signature.java18) { artifact { type = "signature" } }
144144
}
145145

146+
val javaVersionSetting = when (project.name) {
147+
"okcurl", "native-image-tests" -> "11"
148+
else -> "1.8"
149+
}
150+
val projectJvmTarget = JvmTarget.fromTarget(javaVersionSetting)
151+
val projectJavaVersion = JavaVersion.toVersion(javaVersionSetting)
152+
146153
tasks.withType<KotlinCompile> {
147154
compilerOptions {
148-
jvmTarget.set(JvmTarget.JVM_1_8)
155+
jvmTarget.set(projectJvmTarget)
149156
freeCompilerArgs = listOf(
150157
"-Xjvm-default=all",
151158
)
@@ -214,8 +221,8 @@ subprojects {
214221
}
215222

216223
tasks.withType<JavaCompile> {
217-
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
218-
targetCompatibility = JavaVersion.VERSION_1_8.toString()
224+
sourceCompatibility = projectJavaVersion.toString()
225+
targetCompatibility = projectJavaVersion.toString()
219226
}
220227
}
221228

gradle/libs.versions.toml

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ checkStyle = "10.20.2"
55
com-squareup-moshi = "1.15.2"
66
com-squareup-okio = "3.9.1"
77
de-mannodermaus-junit5 = "1.6.0"
8-
graalvm = "22.3.2"
8+
graalvm = "24.1.1"
99
kotlinx-serialization = "1.7.3"
1010
ksp = "2.1.0-1.0.29"
1111
mockserverClient = "5.15.0"
@@ -32,21 +32,22 @@ bouncycastle-bcprov = { module = "org.bouncycastle:bcprov-jdk15to18", version.re
3232
bouncycastle-bctls = { module = "org.bouncycastle:bctls-jdk15to18", version.ref = "org-bouncycastle" }
3333
brotli-dec = "org.brotli:dec:0.1.2"
3434
checkStyle = { module = "com.puppycrawl.tools:checkstyle", version.ref = "checkStyle" }
35-
clikt = "com.github.ajalt.clikt:clikt:4.4.0"
35+
clikt = "com.github.ajalt.clikt:clikt:5.0.2"
3636
codehaus-signature-java18 = "org.codehaus.mojo.signature:java18:1.0"
3737
conscrypt-android = { module = "org.conscrypt:conscrypt-android", version.ref = "org-conscrypt" }
3838
conscrypt-openjdk = { module = "org.conscrypt:conscrypt-openjdk-uber", version.ref = "org-conscrypt" }
3939
converter-moshi = { module = "com.squareup.retrofit2:converter-moshi", version.ref = "retrofit" }
4040
eclipseOsgi = "org.eclipse.platform:org.eclipse.osgi:3.22.0"
4141
findbugs-jsr305 = "com.google.code.findbugs:jsr305:3.0.2"
42+
graal-sdk = { module = "org.graalvm.sdk:graal-sdk", version.ref = "graalvm" }
4243
gradlePlugin-android = "com.android.tools.build:gradle:8.7.3"
4344
gradlePlugin-androidJunit5 = "de.mannodermaus.gradle.plugins:android-junit5:1.11.2.0"
4445
gradlePlugin-animalsniffer = "ru.vyarus:gradle-animalsniffer-plugin:1.7.2"
4546
gradlePlugin-binaryCompatibilityValidator = "org.jetbrains.kotlinx.binary-compatibility-validator:org.jetbrains.kotlinx.binary-compatibility-validator.gradle.plugin:0.16.3"
4647
gradlePlugin-bnd = { module = "biz.aQute.bnd:biz.aQute.bnd.gradle", version.ref = "biz-aQute-bnd" }
4748
gradlePlugin-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.20"
4849
gradlePlugin-errorprone = "net.ltgt.gradle:gradle-errorprone-plugin:4.1.0"
49-
gradlePlugin-graal = "com.palantir.graal:gradle-graal:0.12.0"
50+
gradlePlugin-graalvmBuildTools = "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.10.4"
5051
gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "org-jetbrains-kotlin" }
5152
gradlePlugin-kotlinSerialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "org-jetbrains-kotlin" }
5253
gradlePlugin-mavenPublish = "com.vanniktech:gradle-maven-publish-plugin:0.30.0"

native-image-tests/README.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,12 @@ Native Image Tests
33

44
This executes OkHttp's test suite inside a Graalvm image.
55

6-
Build the Native Image
7-
----------------------
8-
9-
Compile the classes and metadata into a Graalvm native image.
10-
11-
```
12-
./gradlew --info native-image-tests:nativeImage
13-
```
14-
156
Execute
167
-------
178

189
The native image runs JUnit 5 tests in the project.
1910

2011
```
21-
./native-image-tests/build/graal/ConsoleLauncher
12+
./gradlew --info native-image-tests:nativeTest
2213
```
2314

native-image-tests/build.gradle.kts

+33-27
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1-
import org.apache.tools.ant.taskdefs.condition.Os
2-
31
plugins {
4-
id("com.palantir.graal")
2+
id("org.graalvm.buildtools.native")
53
kotlin("jvm")
64
}
75

6+
animalsniffer {
7+
isIgnoreFailures = true
8+
}
9+
10+
val graal by sourceSets.creating
11+
12+
sourceSets {
13+
named("graal") {}
14+
test {
15+
java.srcDirs(
16+
"../okhttp-brotli/src/test/java",
17+
"../okhttp-dnsoverhttps/src/test/java",
18+
"../okhttp-logging-interceptor/src/test/java",
19+
"../okhttp-sse/src/test/java",
20+
)
21+
}
22+
}
23+
824
dependencies {
925
implementation(libs.junit.jupiter.api)
1026
implementation(libs.junit.jupiter.engine)
@@ -21,7 +37,6 @@ dependencies {
2137
implementation(projects.mockwebserver3)
2238
implementation(projects.mockwebserver)
2339
implementation(projects.okhttpJavaNetCookiejar)
24-
implementation(projects.mockwebserver3Junit4)
2540
implementation(projects.mockwebserver3Junit5)
2641
implementation(libs.aqute.resolve)
2742
implementation(libs.junit.jupiter.api)
@@ -30,33 +45,24 @@ dependencies {
3045
implementation(libs.kotlin.test.common)
3146
implementation(libs.kotlin.test.junit)
3247

33-
implementation(libs.nativeImageSvm)
34-
3548
compileOnly(libs.findbugs.jsr305)
36-
}
3749

38-
animalsniffer {
39-
isIgnoreFailures = true
50+
"graalCompileOnly"(libs.nativeImageSvm)
51+
"graalCompileOnly"(libs.graal.sdk)
52+
nativeImageTestCompileOnly(graal.output.classesDirs)
4053
}
4154

42-
sourceSets {
43-
main {
44-
java.srcDirs(
45-
"../okhttp-brotli/src/test/java",
46-
"../okhttp-dnsoverhttps/src/test/java",
47-
"../okhttp-logging-interceptor/src/test/java",
48-
"../okhttp-sse/src/test/java",
49-
)
50-
}
51-
}
55+
graalvmNative {
56+
testSupport = true
5257

53-
graal {
54-
mainClass("okhttp3.RunTestsKt")
55-
outputName("ConsoleLauncher")
56-
graalVersion(libs.versions.graalvm.get())
57-
javaVersion("11")
58+
binaries {
59+
named("test") {
60+
buildArgs.add("--features=okhttp3.nativeImage.TestRegistration")
61+
buildArgs.add("--initialize-at-build-time=org.junit.platform.engine.TestTag")
62+
buildArgs.add("--strict-image-heap")
5863

59-
option("--no-fallback")
60-
option("--report-unsupported-elements-at-runtime")
61-
option("-H:+ReportExceptionStackTraces")
64+
// speed up development testing
65+
buildArgs.add("-Ob")
66+
}
67+
}
6268
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright (C) 2020 Square, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package okhttp3.nativeImage
17+
18+
import org.graalvm.nativeimage.hosted.Feature
19+
20+
class TestRegistration : Feature {
21+
override fun beforeAnalysis(access: Feature.BeforeAnalysisAccess) {
22+
}
23+
}

native-image-tests/src/main/kotlin/okhttp3/DotListener.kt

-77
This file was deleted.

native-image-tests/src/main/kotlin/okhttp3/GenerateClassList.kt

-56
This file was deleted.

0 commit comments

Comments
 (0)