问题
I have problem with building my application using maven-compile-plugin:3.6.0 at jdk9-ea+148.
I am trying to make jdk9 module. Module-info and other classes are getting compiled without problem, but when it comes to default-testCompile it just crashes. When my module-info.java is removed, the it is compiled without problems.
Basically this is the exception I am getting:
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
This is the settings of maven-compiler-plugin I have there
<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>
Does anyone know what to do with this problem to make it work?
回答1:
The exception occurs when Maven tries to read the module-info.class
s class name, which since a recent change was specified to be null. It looks like Maven uses ASM and according to Remi Forax ASM6 should already handle that case.
I suggest looking for an issue in the Maven issue tracker and open one if it can't be found.
回答2:
Using the updated version of the maven-compiler-plugin:3.7.0 shall help you fix this:-
<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>
回答3:
I had the same problem with maven-compile-plugin:3.6.0 at jdk9-ea+149.
I noticed that the actual root cause for this was the test
directory not having a module-info.java
file (I had only added one to the src
directory). As soon as I added a module-info file, the problem went away.
That said, I don't have a clue how the jigsaw directory/module structure should be laid out regarding unit tests - if tests are in a separate module, they can only access the public (exported) API.
来源:https://stackoverflow.com/questions/41061660/compile-tests-using-maven-compiler-and-jdk9-ea148