From 660cdd6dc4602f69933d7e190a17fc7fa2bff02a Mon Sep 17 00:00:00 2001 From: Cedric Champeau Date: Wed, 20 Jul 2022 11:03:41 +0200 Subject: [PATCH 1/2] Fix support for GraalVM 22.2 This commit adds a workaround for GraalVM 22.2 native-image builder running on module path. Because Micronaut uses features which use internal APIs (and no workaround for that), building on 22.2 fails. This commit adds a flag which will let users build by adding a module export. See https://github.com/oracle/graal/pull/4468 --- .../io/micronaut/gradle/aot/MicronautAOTDockerSpec.groovy | 2 +- .../micronaut/gradle/docker/DockerNativeFunctionalTest.groovy | 2 +- .../java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/functional-tests/src/test/groovy/io/micronaut/gradle/aot/MicronautAOTDockerSpec.groovy b/functional-tests/src/test/groovy/io/micronaut/gradle/aot/MicronautAOTDockerSpec.groovy index 02492160..7ca6c37f 100644 --- a/functional-tests/src/test/groovy/io/micronaut/gradle/aot/MicronautAOTDockerSpec.groovy +++ b/functional-tests/src/test/groovy/io/micronaut/gradle/aot/MicronautAOTDockerSpec.groovy @@ -82,7 +82,7 @@ COPY layers/resources /home/app/resources COPY layers/application.jar /home/app/application.jar RUN mkdir /home/app/config-dirs COPY config-dirs/generateResourcesConfigFile /home/app/config-dirs/generateResourcesConfigFile -RUN native-image -cp /home/app/libs/*.jar:/home/app/resources:/home/app/application.jar --no-fallback -H:Name=application -H:ConfigurationFileDirectories=/home/app/config-dirs/generateResourcesConfigFile -H:Class=demo.app.Application +RUN native-image -cp /home/app/libs/*.jar:/home/app/resources:/home/app/application.jar --no-fallback -H:Name=application -J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED -H:ConfigurationFileDirectories=/home/app/config-dirs/generateResourcesConfigFile -H:Class=demo.app.Application FROM frolvlad/alpine-glibc:alpine-3.12 RUN apk update && apk add libstdc++ COPY --from=graalvm /home/app/application /app/application diff --git a/functional-tests/src/test/groovy/io/micronaut/gradle/docker/DockerNativeFunctionalTest.groovy b/functional-tests/src/test/groovy/io/micronaut/gradle/docker/DockerNativeFunctionalTest.groovy index 309cf050..2077b5b2 100644 --- a/functional-tests/src/test/groovy/io/micronaut/gradle/docker/DockerNativeFunctionalTest.groovy +++ b/functional-tests/src/test/groovy/io/micronaut/gradle/docker/DockerNativeFunctionalTest.groovy @@ -573,7 +573,7 @@ COPY layers/resources /home/alternate/resources COPY layers/application.jar /home/alternate/application.jar RUN mkdir /home/alternate/config-dirs COPY config-dirs/generateResourcesConfigFile /home/alternate/config-dirs/generateResourcesConfigFile -RUN native-image -cp /home/alternate/libs/*.jar:/home/alternate/resources:/home/alternate/application.jar --no-fallback -H:Name=application -H:ConfigurationFileDirectories=/home/alternate/config-dirs/generateResourcesConfigFile -H:Class=example.Application +RUN native-image -cp /home/alternate/libs/*.jar:/home/alternate/resources:/home/alternate/application.jar --no-fallback -H:Name=application -J--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED -H:ConfigurationFileDirectories=/home/alternate/config-dirs/generateResourcesConfigFile -H:Class=example.Application FROM frolvlad/alpine-glibc:alpine-3.12 RUN apk update && apk add libstdc++ HEALTHCHECK CMD curl -s localhost:8090/health | grep '"status":"UP"' diff --git a/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java b/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java index ba62aad8..5aa313c1 100644 --- a/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java +++ b/graalvm-plugin/src/main/java/io/micronaut/gradle/graalvm/MicronautGraalPlugin.java @@ -64,6 +64,7 @@ public void apply(Project project) { inf.getIgnoreExistingResourcesConfigFile().convention(true); inf.getRestrictToProjectDependencies().convention(true); })); + options.jvmArgs("--add-exports=org.graalvm.nativeimage.builder/com.oracle.svm.core.jdk=ALL-UNNAMED"); Provider richOutput = project.getProviders().systemProperty(RICH_OUTPUT_PROPERTY); if (richOutput.isPresent()) { options.getRichOutput().convention(richOutput.map(Boolean::parseBoolean)); From 2dc2799f8fa838cbdbd101a27c8e208dbe05a57b Mon Sep 17 00:00:00 2001 From: Cedric Champeau Date: Wed, 20 Jul 2022 12:45:43 +0200 Subject: [PATCH 2/2] Test against latest GraalVM --- .github/workflows/graalvm.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/graalvm.yml b/.github/workflows/graalvm.yml index c5949898..dd2e3c7c 100644 --- a/.github/workflows/graalvm.yml +++ b/.github/workflows/graalvm.yml @@ -20,6 +20,7 @@ jobs: strategy: matrix: java: ['11'] + graalvm: ['latest', 'dev'] steps: # https://github.com/actions/virtual-environments/issues/709 - name: Free disk space @@ -38,7 +39,7 @@ jobs: - name: Setup GraalVM CE uses: graalvm/setup-graalvm@v1 with: - version: '22.1.0' + version: ${{ matrix.graalvm }} java-version: ${{ matrix.java }} components: 'native-image' - name: Build with Gradle