maven aspectJ插件编译错误

时间:2014-08-01 20:10:15

标签: java maven aspectj

我在maven项目中使用maven-aspectJ插件。我想编织cucumber-java库。当我运行maven时,我经常得到

[ERROR] Failed to execute goal
org.codehaus.mojo:aspectj-maven-plugin:1.5:compile (default)
on project junitsampler:
    The artifact info.cukes:cucumber-java referenced in aspectj plugin as
    dependencies and/or directories to weave, is not found the project
    dependencies -> [Help 1]

我的插件配置如下:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.5</version>
    <!-- <dependencies> <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> 
        <version>1.7</version> <scope>system</scope> <systemPath>${tools-jar}</systemPath> 
        </dependency> </dependencies> -->
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>       <!-- use this goal to weave all your main classes -->
                <goal>test-compile</goal>  <!-- use this goal to weave all your test classes -->
            </goals>
        </execution>
    </executions>
    <configuration>
        <source>1.7</source>
        <complianceLevel>1.7</complianceLevel>
        <verbose>true</verbose>
        <showWeaveInfo>true</showWeaveInfo>
        <target>1.7</target>
        <forceAjcCompile>true</forceAjcCompile>
        <weaveDirectories>
            <weaveDirectory>C:/Users/shenv/workspace/junitsampler/target/classes/cucumber</weaveDirectory>
        </weaveDirectories>

        <!-- <weaveDependencies> <weaveDependency> <groupId>com.autodesk.dm.wipdata.jmeter</groupId> 
            <artifactId>junitsampler</artifactId> </weaveDependency> <weaveDependency> 
            <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> </weaveDependency> -->
        <weaveDependencies>
            <weaveDependency>
                <groupId>info.cukes</groupId>
                <artifactId>cucumber-java</artifactId>
            </weaveDependency>
        </weaveDependencies>
    </configuration>
</plugin>

我检查了pom.xml,依赖项就在那里。我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

您的<weaveDependency>应该引用您pom.xml中已定义的依赖关系。你是否在<dependencies>下完成了这项工作?像这样:

<project>
    <dependencies>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.1.8</version>
        </dependency>
        <!-- (...) -->
    </dependencies>
    <!-- (...) -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.5</version>
                <!-- (...) -->
                <configuration>
                    <!-- (...) -->
                    <weaveDependencies>
                        <weaveDependency>
                            <groupId>info.cukes</groupId>
                            <artifactId>cucumber-java</artifactId>
                        </weaveDependency>
                    </weaveDependencies>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

另见AspectJ Maven plugin documentation