使用apt-maven-plugin生成QueryDSL的Q ...类时,maven构建在NullPointerException
中失败,SimpleSerializerConfig
- 但仅限于3.1.0以后的maven版本。
我们已经尝试调试maven版本,但这并没有得出任何结论。
maven配置如下所示:
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>target/generated-sources/java</outputDirectory>
<processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
<logOnlyOnError>true</logOnlyOnError>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl.version}</version>
</dependency>
<dependency>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<classifier>apt</classifier>
<version>${querydsl.version}</version>
</dependency>
</dependencies>
</plugin>
${querydsl.version}
为2.9.0 - 使用较新的版本无法解决问题。
确切的堆栈跟踪是
java.lang.RuntimeException: java.lang.NullPointerException
at com.sun.tools.javac.main.Main.compile(Main.java:469)
at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:132)
at com.mysema.maven.apt.AbstractProcessorMojo.execute(AbstractProcessorMojo.java:314)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
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:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:318)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:414)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:357)
Caused by: java.lang.NullPointerException
at com.mysema.query.codegen.SimpleSerializerConfig.getConfig(SimpleSerializerConfig.java:29)
at com.mysema.query.apt.DefaultConfiguration.<init>(DefaultConfiguration.java:129)
at com.mysema.query.apt.jpa.JPAConfiguration.<init>(JPAConfiguration.java:69)
at com.mysema.query.apt.jpa.JPAAnnotationProcessor.createConfiguration(JPAAnnotationProcessor.java:46)
at com.mysema.query.apt.AbstractQuerydslProcessor.process(AbstractQuerydslProcessor.java:102)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:793)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:722)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1700(JavacProcessingEnvironment.java:97)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1029)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1163)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1108)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:824)
at com.sun.tools.javac.main.Main.compile(Main.java:439)
... 23 more
答案 0 :(得分:3)
当构建中存在依赖冲突时,通常会发生此异常。尝试禁用apt执行,看看构建中是否还有其他问题。
答案 1 :(得分:0)
我们也碰到了这个。我们注意到原因直接与注释有关。我们在Maven本身能够解决的类中添加了一个注释,但mysema却没有。我们明确地将编译依赖项添加到有问题的pom中,一切都解决了。
答案 2 :(得分:0)
只是分享我的经验与类似的错误,但不同的原因,以防其他人遇到这种情况。
从测试范围的依赖项向src / main / java中的类添加注释后出现相同的错误。 Eclipse并没有抱怨,因为m2eclipse并不擅长区分编译和测试范围的依赖关系,只是将所有依赖项添加到项目类路径中,无论范围如何。
要查看实际的编译错误,我必须执行以下步骤:
mvn compile
(不clean
不删除步骤1中生成的类)