maven aspectj编织NullPointerException

时间:2016-05-30 10:20:38

标签: java spring maven compiler-errors aspectj

我有一个使用MyEclipse创建的Spring MVC应用程序,它包含生成的源代码以及我自己的源代码,以及我在生成的类上定义的方面。在MyEclipse中编译好的一切,但我现在想切换到Maven以便使用持续集成服务器。

我一直在摆弄pom.xml很长一段时间了,我撞到了一堵墙似乎无法绕过。当maven到达编织方面的那一刻,我得到以下异常(为了简洁起见,只是前几行):

[INFO] [aspectj:compile {execution: default}]
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[ERROR] ABORT
May 30, 2016 11:48:05 AM org.aspectj.weaver.tools.Jdk14Trace info
INFO: Dumping to /var/atlassian/application-data/bamboo/xml-data/build-dir/OW-BUIL-JOB1/./ajcore.20160530.114805.876.txt
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] AJC compiler errors:
abort ABORT -- (NullPointerException) null
null
java.lang.NullPointerException
    at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.resolveAnnotations(AnnotationDiscoveryVisitor.java:238)
    at org.aspectj.org.eclipse.jdt.internal.compiler.apt.dispatch.AnnotationDiscoveryVisitor.visit(AnnotationDiscoveryVisitor.java:217)
    at org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1348)
    at org.aspectj.org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:748)
    ...

我的pom.xml太长了,无法将其粘贴到此处,但构建部分如下(如果您想查看一些依赖项,请告诉我):

<build>
    <directory>bin</directory>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src</source>
                            <source>generated</source>
                            <source>resources</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <excludes>
                    <exclude>main/</exclude>
                    <exclude>test/</exclude>
                </excludes>
                <useIncrementalCompilation>true</useIncrementalCompilation>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.8</version>
            <configuration>
                <showWeaveInfo>true</showWeaveInfo>
                <source>1.6</source>
                <target>1.6</target>
                <Xlint>ignore</Xlint>
                <complianceLevel>1.6</complianceLevel>
                <encoding>UTF-8</encoding>
                <verbose>true</verbose>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aspects</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
            </configuration>
            <executions>
                <execution>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <configuration>
                <webXml>${project.basedir}/WebRoot/WEB-INF/web.xml</webXml>
                <warName>oligoWorld</warName>
                <outputDirectory>${project.basedir}</outputDirectory>
            </configuration>
        </plugin>
    </plugins>
    <pluginManagement>
        <plugins>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>aspectj-maven-plugin</artifactId>
                                    <versionRange>[1.8,)</versionRange>
                                    <goals>
                                        <goal>compile</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

任何人看到任何错误或遗失都可能导致该异常?仅供参考,我的aspectj依赖项(aspectjrt,aspectjtools和aspectjweaver)的版本是1.8.7。

1 个答案:

答案 0 :(得分:1)

我似乎找到了问题。在pom.xml中,我在aspectj-maven-plugin定义之外的pom文件的dependencies部分中列出了aspectjtools的依赖关系以及所有其他依赖关系。相反,我把它移到了插件中;另外,我更改了aspectj库&#39;版本为1.8.9,因为看起来1.8.7表现出类似于我发现的错误。在此之后,一切正常。所以这里是我对aspectj-maven-plugin的修改后的定义供参考:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.8</version>
            <dependencies> <!-- The change that fixed it starts here... -->
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjtools</artifactId>
                    <version>1.8.9</version>
                </dependency>
            </dependencies> <!-- ...and ends here. -->
            <configuration>
                <showWeaveInfo>true</showWeaveInfo>
                <source>1.6</source>
                <target>1.6</target>
                <Xlint>ignore</Xlint>
                <complianceLevel>1.6</complianceLevel>
                <encoding>UTF-8</encoding>
                <verbose>true</verbose>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aspects</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
            </configuration>
        </plugin>