在用Maven构建的项目中扩展java.base

j9per5c4  于 2023-05-28  发布在  Maven
关注(0)|答案(1)|浏览(132)

Maven 3.9.0 invalid flag --patch-module是我在扩展java.lang包的项目上运行mvn clean compile时得到的。当我运行javac --patch-module java.base=src <path-to-source>时,一切都很好。
原因是- Maven使用com.sun.tools.javac.api.JavacTool,当解析<compilerArgs>时,它只使用BASIC选项组,而--patch-moduleFILEMANAGER组中。这会在mvn clean compile期间引发illegal flag异常。
有谁知道我怎么能让它与Maven一起工作吗?我不喜欢使用javac命令行工具来创建CI管道。
项目结构如下:src -> main -> java -> java.lang ->
pom.xml看起来像:

<plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.10.1</version>
                <configuration>
                    <source>${java.source.sdk}</source>
                    <target>${java.source.sdk}</target>
                    <compilerArgs>
                        <arg>--patch-module java.base=src</arg>
                    </compilerArgs>
                </configuration>
            </plugin>
        </plugins>

Maven版本:

Maven home: /opt/homebrew/Cellar/maven/3.9.0/libexec
Java version: 18, vendor: Oracle Corporation, runtime: /Users/<username>/Library/Java/JavaVirtualMachines/openjdk-18/Contents/Home
Default locale: en_RS, platform encoding: UTF-8
OS name: "mac os x", version: "12.6.2", arch: "aarch64", family: "mac"

使用JDK 19 ->相同的结果。使用Maven 3.10.1 ->相同的结果。
完整错误为:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project commons-bootstrap: Fatal error compiling: error: invalid flag: --patch-module java.base=src -> [Help 1]
异常堆栈跟踪:

Caused by: java.lang.IllegalArgumentException: error: invalid flag: --patch-module java.base=src
    at com.sun.tools.javac.main.Arguments.reportDiag (Arguments.java:889)
    at com.sun.tools.javac.main.Arguments.doProcessArgs (Arguments.java:395)
    at com.sun.tools.javac.main.Arguments.processArgs (Arguments.java:347)
    at com.sun.tools.javac.main.Arguments.init (Arguments.java:246)
    at com.sun.tools.javac.api.JavacTool.getTask (JavacTool.java:191)
    at com.sun.tools.javac.api.JavacTool.getTask (JavacTool.java:119)
    at com.sun.tools.javac.api.JavacTool.getTask (JavacTool.java:68)
    at org.codehaus.plexus.compiler.javac.JavaxToolsCompiler.compileInProcess (JavaxToolsCompiler.java:135)
    at org.codehaus.plexus.compiler.javac.JavacCompiler.performCompile (JavacCompiler.java:182)
    at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1209)
    at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:198)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:342)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:330)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:175)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:76)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:163)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:160)
    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:260)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:172)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:100)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:821)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:270)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:577)
    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)
q35jwt9p

q35jwt9p1#

Maven将参数解析为一个带有嵌入空格的长参数。
这就是它应该看起来的样子:

<compilerArgs>
    <arg>--patch-module</arg>
    <arg>java.base=src</arg>
</compilerArgs>

例如,请参阅Maven文档。

相关问题