Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maven process-aot fails when compiler plugin has been configured with --enable-preview #33012

Closed
wssy001 opened this issue Nov 5, 2022 · 2 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@wssy001
Copy link

wssy001 commented Nov 5, 2022

I noticed you have moved all of the graalvm native-maven-plugin configuration to spring-boot-parent, and I also found this
I follow it ,wrote this to my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.0-RC1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <java.version>19</java.version>
        <maven.compiler.source>19</maven.compiler.source>
        <maven.compiler.target>19</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <image>
                        <buildpacks>
                            <buildpack>gcr.io/paketo-buildpacks/bellsoft-liberica:9.9.0-ea</buildpack>
                            <buildpack>gcr.io/paketo-buildpacks/java-native-image</buildpack>
                        </buildpacks>
                    </image>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerArgs>
                        <arg>--enable-preview</arg>
                        <arg>--add-modules jdk.incubator.concurrent</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <argLine>--enable-preview</argLine>
                    <argLine>--add-modules jdk.incubator.concurrent</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.graalvm.buildtools</groupId>
                <artifactId>native-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <buildArgs combine.children="append">
                        <buildArg>
                            --enable-preview
                        </buildArg>
                    </buildArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

But it did work.here is the log

[INFO] Scanning for projects...
[INFO] Found GraalVM installation from GRAALVM_HOME variable.
[INFO] 
[INFO] -----------------------< com.example:loom-test >------------------------
[INFO] Building loom-test 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] >>> native-maven-plugin:0.9.16:compile (default-cli) > package @ loom-test >>>
[INFO] 
[INFO] --- native-maven-plugin:0.9.16:add-reachability-metadata (add-reachability-metadata) @ loom-test ---
[INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.4.4]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for ch.qos.logback:logback-classic:1.4.4]: Configuration directory is ch.qos.logback/logback-classic/1.4.1
[INFO] [graalvm reachability metadata repository for org.apache.tomcat.embed:tomcat-embed-core:10.0.27]: Configuration directory not found. Trying latest version.
[INFO] [graalvm reachability metadata repository for org.apache.tomcat.embed:tomcat-embed-core:10.0.27]: Configuration directory is org.apache.tomcat.embed/tomcat-embed-core/10.0.20
[INFO] 
[INFO] --- maven-resources-plugin:3.3.0:resources (default-resources) @ loom-test ---
[INFO] Copying 1 resource
[INFO] Copying 6 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:compile (default-compile) @ loom-test ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:3.3.0:testResources (default-testResources) @ loom-test ---
[INFO] Not copying test resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.10.1:testCompile (default-testCompile) @ loom-test ---
[INFO] Not compiling test sources
[INFO] 
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ loom-test ---
[INFO] Tests are skipped.
[INFO] 
[INFO] --- spring-boot-maven-plugin:3.0.0-RC1:process-aot (process-aot) @ loom-test ---

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::            (v3.0.0-RC1)

2022-11-05T13:49:51.023+08:00  INFO 8004 --- [           main] c.example.loomtest.LoomTestApplication   : Starting LoomTestApplication using Java 19.0.1 on AlexdeAir.lan with PID 8004 (/Users/alexpetertyler/workspace/SpringBoot/loom-test/target/classes started by alexpetertyler in /Users/alexpetertyler/workspace/SpringBoot/loom-test)
2022-11-05T13:49:51.028+08:00  INFO 8004 --- [           main] c.example.loomtest.LoomTestApplication   : No active profile set, falling back to 1 default profile: "default"
Exception in thread "main" java.lang.UnsupportedClassVersionError: Preview features are not enabled for com/example/loomtest/controller/TestController (class file version 63.65535). Try running with '--enable-preview'
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:495)
        at java.base/java.lang.Class.forName(Class.java:474)
        at org.springframework.util.ClassUtils.forName(ClassUtils.java:283)
        at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:461)
        at org.springframework.context.support.PostProcessorRegistrationDelegate$MergedBeanDefinitionPostProcessorInvoker.resolveBeanType(PostProcessorRegistrationDelegate.java:482)
        at org.springframework.context.support.PostProcessorRegistrationDelegate$MergedBeanDefinitionPostProcessorInvoker.invokeMergedBeanDefinitionPostProcessors(PostProcessorRegistrationDelegate.java:440)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeMergedBeanDefinitionPostProcessors(PostProcessorRegistrationDelegate.java:317)
        at org.springframework.context.support.GenericApplicationContext.refreshForAotProcessing(GenericApplicationContext.java:428)
        at org.springframework.context.aot.ApplicationContextAotGenerator.lambda$processAheadOfTime$0(ApplicationContextAotGenerator.java:54)
        at org.springframework.context.aot.ApplicationContextAotGenerator.withCglibClassHandler(ApplicationContextAotGenerator.java:67)
        at org.springframework.context.aot.ApplicationContextAotGenerator.processAheadOfTime(ApplicationContextAotGenerator.java:53)
        at org.springframework.context.aot.ContextAotProcessor.performAotProcessing(ContextAotProcessor.java:106)
        at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:84)
        at org.springframework.context.aot.ContextAotProcessor.doProcess(ContextAotProcessor.java:49)
        at org.springframework.context.aot.AbstractAotProcessor.process(AbstractAotProcessor.java:82)
        at org.springframework.boot.SpringApplicationAotProcessor.main(SpringApplicationAotProcessor.java:76)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.122 s
[INFO] Finished at: 2022-11-05T13:49:52+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.0-RC1:process-aot (process-aot) on project loom-test: Process terminated with exit code: 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Environment:

openjdk version "19.0.1" 2022-10-18
OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 19.0.1+10-jvmci-22.3-b08)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 19.0.1+10-jvmci-22.3-b08, mixed mode, sharing)
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 5, 2022
@wilkinsona wilkinsona changed the title Springboot 3.0 RC1 native-maven-plugin passing arguments to native image build issue process-aot fails when compiler plugin has been configured with --enable-preview Nov 5, 2022
@wilkinsona
Copy link
Member

You can get past that initial problem by adding <jvmArguments>--enable-preview</jvmArguments> to the configuration of spring-boot-maven-plugin. With that change in place, AOT processing can be performed. Unfortunately, compilation of the AOT-generated source then fails:

Caused by: java.lang.IllegalStateException: Unable to compile generated source
class file for /Users/awilkinson/Downloads/gh-33012/target/classes/com/example/gh33012/Gh33012Application.class uses preview features of Java SE 19.
  (use --enable-preview to allow loading of class files which contain preview features) /Users/awilkinson/Downloads/gh-33012/target/spring-aot/main/sources/com/example/gh33012/Gh33012Application__BeanDefinitions.java -1:-1
    at org.springframework.boot.maven.AbstractAotMojo.compileSourceFiles (AbstractAotMojo.java:135)
    at org.springframework.boot.maven.ProcessAotMojo.executeAot (ProcessAotMojo.java:95)
    at org.springframework.boot.maven.AbstractAotMojo.execute (AbstractAotMojo.java:96)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:370)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:351)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:171)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:163)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:578)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:578)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:47)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:156)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:72)

This can't be addressed by configuration in the pom file and will require a change in Boot's Maven plugin.

@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 8, 2022
@wilkinsona wilkinsona added this to the 3.0.x milestone Nov 8, 2022
@scottfrederick scottfrederick self-assigned this Nov 10, 2022
@scottfrederick scottfrederick changed the title process-aot fails when compiler plugin has been configured with --enable-preview Maven process-aot fails when compiler plugin has been configured with --enable-preview Nov 11, 2022
@scottfrederick scottfrederick modified the milestones: 3.0.x, 3.0.0 Nov 14, 2022
@scottfrederick
Copy link
Contributor

With the latest Spring Boot 3.0.0-SNAPSHOT builds, this will now work with the following configuration:

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <jvmArguments>--enable-preview</jvmArguments>
                    <compilerArguments>--enable-preview</compilerArguments>
                </configuration>
            </plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants