4

我在使用 aspectj-maven-plugin 构建 AspectJ 项目时遇到问题

该项目只有一个方面:

src/main/java/org/lightforge/config/ConfigurationAspect.aj

ConfigurationAspect.aj 根据 AspectJ in Action 2nd Ed 的 Ch5 做了一些成员介绍。

我正在使用带有 AJDT 的 Eclipse 并根据http://mojo.codehaus.org/aspectj-maven-plugin/设置 pom.xml

虽然,当我运行 Maven 安装(运行方式-> Maven 安装)时,显然 aspectj-maven-plugin:compile 永远不会执行。

以下是我的 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>lightforge</groupId>
<artifactId>lightforge-config</artifactId>
<version>0.0.6-SNAPSHOT</version>
<name>lightforge-config</name>
<dependencies>
    <dependency>
        <groupId>commons-configuration</groupId>
        <artifactId>commons-configuration</artifactId>
        <version>1.9</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.6</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.6.11</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>1.6.11</version>
    </dependency>
</dependencies>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>aspectj-maven-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <outxml>true</outxml>
                    <ajdtBuildDefFile>build.ajproperties</ajdtBuildDefFile>
                    <verbose>true</verbose>
                    <aspectDirectory>src/main/java</aspectDirectory>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>
</build>
</project>

这是我的 build.ajproperties:

src.includes = src/main/java/,\
           src/main/resources/,\
           src/test/java/,\
           src/test/resources/
src.excludes = src/main/resources/**,\
           src/test/resources/**

最后,这是构建日志:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building lightforge-config 0.0.6-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ lightforge-config ---
[debug] execute contextualize
[WARNING] Using platform encoding (US-ASCII actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ lightforge-config ---
[WARNING] File encoding has not been set, using platform encoding US-ASCII, i.e. build is platform dependent!
[INFO] Compiling 2 source files to /Users/jjcamachosanchez/Dropbox/Jhon/Dev/Eclipse/workspace/lightforge-config/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/jjcamachosanchez/Dropbox/Jhon/Dev/Eclipse/workspace/lightforge-config/src/main/java/org/lightforge/config/TestSubject.java:[12,9] cannot find symbol
symbol  : method getPropertyInt(java.lang.String)
location: class org.lightforge.config.TestSubject
[ERROR] /Users/jjcamachosanchez/Dropbox/Jhon/Dev/Eclipse/workspace/lightforge-config/src/main/java/org/lightforge/config/TestSubject.java:[16,9] cannot find symbol
symbol  : method getPropertyLong(java.lang.String)
location: class org.lightforge.config.TestSubject
[ERROR] /Users/jjcamachosanchez/Dropbox/Jhon/Dev/Eclipse/workspace/lightforge-config/src/main/java/org/lightforge/config/TestSubject.java:[20,9] cannot find symbol
symbol  : method getPropertyString(java.lang.String)
location: class org.lightforge.config.TestSubject
[INFO] 3 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.286s
[INFO] Finished at: Mon Jul 29 00:14:56 COT 2013
[INFO] Final Memory: 9M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project lightforge-config: Compilation failure: Compilation failure:
[ERROR] /Users/jjcamachosanchez/Dropbox/Jhon/Dev/Eclipse/workspace/lightforge-config/src/main/java/org/lightforge/config/TestSubject.java:[12,9] cannot find symbol
[ERROR] symbol  : method getPropertyInt(java.lang.String)
[ERROR] location: class org.lightforge.config.TestSubject
[ERROR] /Users/jjcamachosanchez/Dropbox/Jhon/Dev/Eclipse/workspace/lightforge-config/src/main/java/org/lightforge/config/TestSubject.java:[16,9] cannot find symbol
[ERROR] symbol  : method getPropertyLong(java.lang.String)
[ERROR] location: class org.lightforge.config.TestSubject
[ERROR] /Users/jjcamachosanchez/Dropbox/Jhon/Dev/Eclipse/workspace/lightforge-config/src/main/java/org/lightforge/config/TestSubject.java:[20,9] cannot find symbol
[ERROR] symbol  : method getPropertyString(java.lang.String)
[ERROR] location: class org.lightforge.config.TestSubject
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

请帮我,

4

3 回答 3

5

乔恩,不确定你是否得到了答案,由于我无法解释的原因,删除插件周围的 pluginManagement 标记似乎有效。

于 2013-10-13T13:23:30.787 回答
3

您必须禁用 maven-compiler-plugin 以便使用 ajc 编译器而不是 javac:

        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <executions>
                <execution>
                    <id>default-testCompile</id>
                    <phase>none</phase>
                </execution>
                <execution>
                    <id>default-compile</id>
                    <phase>none</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
于 2014-11-02T17:02:14.283 回答
0

好的...首先有两件事与您的问题无关:

  1. 无需使用 build.ajproperties 文件。这是自动计算的。
  2. 您可能希望为testCompile执行添加一个目标,否则您的测试类将不会被编织。

答案在于您将 AspectJ 与 ITD 一起使用,但 maven 编译器在 AspectJ 编译器之前运行并且失败(因为尚未编织 ITD)。看起来没有一个干净的答案,但看看这个问题:

如何禁用 maven-compiler-plugin?

我从未跟进并尝试过那里建议的所有解决方案,但我确实知道以下内容适用于单 pom 场景:

  1. <aspectDirectory>src/main/java</aspectDirectory><aspectDirectory>src/main/aspect</aspectDirectory>
  2. 将所有源文件从src/main/javasrc/main/aspect移动(或至少移动依赖于正在编织的 ITD 的文件)。
于 2013-07-29T19:14:47.950 回答