由于Aspect,Junit失败了

时间:2013-02-12 20:55:39

标签: maven aspectj compile-time load-time-weaving compile-time-weaving

我有一个基于注释的自定义安全框架。当遇到方法的安全注释时,我使用aspectj maven插件来编织方面。

我使用jenkins构建项目,并设置了aspectj maven插件目标以供编译,如下所示。

    <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.4</version>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjrt</artifactId>
                    <version>1.6.5</version>
                </dependency>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjtools</artifactId>
                    <version>1.6.5</version>
                </dependency>
            </dependencies>
            <configuration>
                <showWeaveInfo>true</showWeaveInfo>
                <complianceLevel>1.6</complianceLevel>
                <!-- <weaveDirectories> <weaveDirectory>${project.build.directory}/classes</weaveDirectory> 
                    </weaveDirectories> -->
            </configuration>
            <executions>
                <execution>
                    <!-- Compile and weave aspects after all classes compiled by javac -->
                    <phase>process-classes</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

当junit运行时出现问题。由于它已经在方法中编织了与安全性相关的注释,因此单元测试失败。

有没有办法可以让junits工作然后进行aspectj编织? 由于我单独使用.aj文件,我不确定如何设置加载时间编织。

对此有任何帮助表示赞赏。

此致

2 个答案:

答案 0 :(得分:0)

我认为你需要为你的目标添加测试编译。

<goals>
    <goal>compile</goal>
    <goal>test-compile</goal>
</goals>

答案 1 :(得分:0)

我将我的maven目标重组为

clean compile test aspectj:compile

所以在测试了aspectj之后,编织就完成了,这就是我想要的。

相关问题