Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven doesn't weave aspectj code

I'm facing problems to build an aspect project in eclipse with maven. When I run maven through eclipse "Run As > Maven build" I obtain this message: <...>/Clazz.java:[5,32] error: cannot find symbol. So, it looks like aspectj is not weaving the code through maven.

I distilled the problem until have class and an aspect that defines an intertype attribute in the mentioned class, as follows:

public class Clazz {
    public static void main(String[] args) {
        System.out.println(new Clazz().string);
    }
}

public aspect Aspect {

    public String Clazz.string = "string";

}

The pom.xml looks like this:

  <dependencies>
<dependency>
  <groupId>org.aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>1.7.3</version>
</dependency>

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
like image 791
Bruno Cartaxo Avatar asked May 10 '26 20:05

Bruno Cartaxo


1 Answers

The problem appears to be that the maven-compiler-plugin doesn't know to get out of the way when you have an AspectJ compile and throws errors that kill the build before ajc gets a chance to pull in the ITDs. My solution has been to disable maven-compiler-plugin entirely and let ajc handle compiling the .java files:

<!-- disable compiler because compiler chokes on ITDs -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <executions>
        <execution>
            <id>default-testCompile</id>
            <phase>none</phase>
        </execution>
        <execution>
            <id>default-compile</id>
            <phase>none</phase>
        </execution>
    </executions>
</plugin>
like image 161
chrylis -cautiouslyoptimistic- Avatar answered May 12 '26 10:05

chrylis -cautiouslyoptimistic-