【问题标题】:maven aspectj weaving NullPointerExceptionmaven aspectj 编织 NullPointerException
【发布时间】:2016-05-30 10:20:37
【问题描述】:

我有一个使用 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。

【问题讨论】:

  • 谢谢,但不是真的。编译是在持续集成服务器 (Bamboo) 上进行的,而不是在 Eclipse 内部,因此这些步骤不适用。
  • 您应该将您的解决方案移至下面的答案。
  • @NándorElődFekete 完成。

标签: java spring maven compiler-errors aspectj


【解决方案1】:

我似乎找到了问题所在。在 pom.xml 中,我列出了 aspectjtools 的依赖项,以及 pom 文件的依赖项部分中的所有其他依赖项,在 aspectj-maven-plugin 定义之外。相反,我将它移到了插件中;另外,我将 aspectj 库的版本更改为 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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-07
    • 1970-01-01
    相关资源
    最近更新 更多