running Maven compiler plugin (3.11.0) in fork mode throws exception when using incubating module

  Kiến thức lập trình

I have a Maven project. I can compile it successfully with

<fork>false</false> <!-- this is the default setting of fork. see: https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#fork -->
<compilerArgs combine.children="append">
                    <arg>--enable-preview</arg>
                    <arg>--add-modules</arg>
                    <arg>jdk.incubator.vector</arg>                    

However I am trying to use the checker framework and it requires setting fork to true. [1]. But as soon as I try to do this:

<fork>true</false> 
<compilerArgs combine.children="append">
                    <arg>--enable-preview</arg>
                    <arg>--add-modules</arg>
                    <arg>jdk.incubator.vector</arg>                    

I now get an error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project xxx-utils: Compilation failure: Compilation failure:
[ERROR] using incubating module(s): jdk.incubator.vector
[ERROR] using incubating module(s): jdk.incubator.vector
[ERROR] using incubating module(s): jdk.incubator.vector

Maven callstack:

Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1214)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:193)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)

Line that is causing the exception [2]:

throw new CompilationFailureException(warnings);

command-line options Maven is passing to javac:

[DEBUG] Excutable:
[DEBUG]  /Library/Java/jdk-21.0.1.jdk/Contents/Home/bin/javac
[DEBUG] Command line options:
[DEBUG] -d /Users/xxx/code/xxx/utils/target/classes -classpath ... -sourcepath ... -s /Users/xxx/code/xxx/utils/target/generated-sources/annotations -processor org.checkerframework.checker.nullness.NullnessChecker -processorpath ... -g -parameters --release 21 -encoding UTF-8 -Xmaxerrs 10000 -Xmaxwarns 10000 -Awarns --enable-preview --add-modules jdk.incubator.vector

Why is it an error all of a sudden to use an incubating module? It seems to be that compiler warnings seem to be manifesting as error. How can I fix this?

LEAVE A COMMENT