我在使用maven-compile-plugin构建我的应用程序时遇到问题:3.6.0 at jdk9-ea + 148。
我正在尝试制作jdk9模块。模块信息和其他类正在编译而没有问题,但是当涉及到default-testCompile时,它就会崩溃。当我的module-info.java被删除时,它的编译没有问题。
基本上这是我得到的例外:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:testCompile (default-testCompile) on project bar: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:testCompile failed. NullPointerException -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:testCompile (default-testCompile) on project bar: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:testCompile failed. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) at org.apache.maven.cli.MavenCli.main(MavenCli.java:199) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:538) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:testCompile failed. at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:145) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207) ... 20 more Caused by: java.lang.NullPointerException at org.apache.maven.plugin.compiler.AsmModuleInfoParser.getModuleName(AsmModuleInfoParser.java:48) at org.apache.maven.plugin.compiler.TestCompilerMojo.preparePaths(TestCompilerMojo.java:259) at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:742) at org.apache.maven.plugin.compiler.TestCompilerMojo.execute(TestCompilerMojo.java:164) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) ... 21 more
这是我在那里的maven-compiler-plugin的设置
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.9</source>
<target>1.9</target>
<compilerArgument>-Xlint:all</compilerArgument>
</configuration>
</plugin>
</plugins>
是否有人知道如何处理此问题才能使其正常工作?
答案 0 :(得分:2)
当Maven尝试读取module-info.class
的类名时会发生异常,因为a recent change被指定为null。看起来Maven使用ASM并且根据Remi Forax ASM6 should already handle that case。
我建议在Maven问题跟踪器中查找问题,如果找不到它,请打开一个问题。
答案 1 :(得分:1)
使用maven-compiler-plugin:3.7.0
的更新版本可以帮助您解决此问题: -
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>9</source>
<target>9</target>
<compilerArgument>-Xlint:all</compilerArgument>
</configuration>
</plugin>
</plugins>
答案 2 :(得分:0)
我遇到了与maven-compile-plugin相同的问题:3.6.0 at jdk9-ea + 149。
我注意到,实际的根本原因是test
目录没有module-info.java
文件(我只在src
目录中添加了一个)。一旦我添加了模块信息文件,问题就消失了。
那就是说,我不知道如何在单元测试中布置拼图目录/模块结构 - 如果测试是在一个单独的模块中,他们只能访问公共(导出)API。 / p>