4

I am having problems building an AspectJ project using the aspectj-maven-plugin

the project has only one aspect:

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

ConfigurationAspect.aj does some members introduction according to Ch5 of AspectJ in Action 2nd Ed.

I am using Eclipse with AJDT and set pom.xml according to http://mojo.codehaus.org/aspectj-maven-plugin/

Although, when I run Maven install (Run As -> Maven Install), apparently aspectj-maven-plugin:compile is never executed.

Following is my 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>

This is my build.ajproperties:

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

Finally, this is the Build Log:

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

Please Help me,

Jhon

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
Jhon Camacho
  • 63
  • 1
  • 5

3 Answers3

5

Jon, Not sure if you got your answer and for reasons I cannot explain, removing the pluginManagement tag around the plugins seems to work.

zoostar
  • 249
  • 1
  • 3
  • 11
  • 1
    Wow, this solved my problem, thanks! I started with a POM generated by Roo that contains the "pluginManagement" tag. Not sure why removing this tag helps. – Matthias Wuttke Jan 10 '14 at 15:24
  • pluginManagement define plugin configuration but doesn't apply them. If you need those plugin enabled in a pom, it must be applied outside the plugin management section, but style could be defined in it. it is especially useful when having multimodules project – Jonatan Cloutier Nov 08 '19 at 21:18
3

You have to disable maven-compiler-plugin so that ajc compiler is used and not 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>
Jonatan Cloutier
  • 899
  • 9
  • 26
0

OK...two things first that are not related to your problem:

  1. There's no need to use a build.ajproperties file. This is calculated automatically.
  2. You'll probably want to add a testCompile goal to the executions, otherwise your test classes won't be woven.

The answer lies with the fact that you are using AspectJ with ITDs, but the maven compiler runs before the AspectJ compiler and fails (because ITDs have not been woven). It doesn't look like there is a clean answer, but have a look at this question:

How do I disable the maven-compiler-plugin?

I never followed up and tried all of the solutions suggested there, but I do know that the following would work in single-pom scenario:

  1. <aspectDirectory>src/main/java</aspectDirectory> to <aspectDirectory>src/main/aspect</aspectDirectory>
  2. move all source files from src/main/java to src/main/aspect (or at least move the files that rely on the ITDs being woven).
Community
  • 1
  • 1
Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • Thanks four fast respose. Unfortunately, it did not work. Now I see the "BUILD SUCCESS" message, though the aspectj-maven-plugin is not executed and the .jar only content is the META-INF directory. – Jhon Camacho Jul 29 '13 at 23:00
  • Please find the project layout, pom and log in the following address: [link](https://www.dropbox.com/sh/pbob7wxtdki70vq/zcXVmmFE32) – Jhon Camacho Jul 29 '13 at 23:11