英文:
Extending java.base in a project built with Maven
问题
Maven 3.9.0在运行mvn clean compile
时出现无效标志--patch-module
的问题,这是因为该项目扩展了java.lang
包。当我运行javac --patch-module java.base=src <path-to-source>
时,一切正常。
原因是 - Maven使用com.sun.tools.javac.api.JavacTool
,当解析<compilerArgs>
时,它仅使用BASIC
选项组,而--patch-module
位于FILEMANAGER
组。这会在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版本:
Apache Maven 3.9.0 (9b58d2bad23a66be161c4664ef21ce219c2c8584)
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.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)
英文:
Maven 3.9.0 invalid flag --patch-module
is what I get when I run mvn clean compile
on my project that extends java.lang
package. When I run javac --patch-module java.base=src <path-to-source>
all is good.
The reason is - Maven uses com.sun.tools.javac.api.JavacTool
which when parsing <compilerArgs>
is using only the BASIC
Option group and --patch-module
is in the FILEMANAGER
group. This raises an illegal flag
exception during mvn clean compile
.
Does anyone know how I can get it to work with Maven? I'd prefer not to make my CI pipeline using javac
command line tool.
Project structure is like:
src -> main -> java -> java.lang -> <classes>
pom.xml
looks like:
<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 version:
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"
Used JDK 19 -> same result. Used Maven 3.10.1 -> same result.
Full error is:
[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]
Exception stacktrace:
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)
答案1
得分: 1
Maven将参数解析为一个带有嵌入式空格的长参数。
应该看起来像这样:
<compilerArgs>
<arg>--patch-module</arg>
<arg>java.base=src</arg>
</compilerArgs>
请参阅Maven文档以获取示例。
英文:
Maven parses the argument as one long argument with embedded whitespace.
This is what it is supposed to look like:
<compilerArgs>
<arg>--patch-module</arg>
<arg>java.base=src</arg>
</compilerArgs>
See the Maven documentation for example.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论