Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[ajdt-dev] m2e connector and post-compilation weaving

Hi !

I currently have a Maven project that uses post-compilation weaving (aka binary weaving).
When building with Maven, everything works as expected.
When building with Eclipse, nothing seems to be weaved.

I'm using Spring's "AbstractTransactionAspect" aspect in conjunction with the @Transactional annotation for my tests.

=========
public class MyClass 
{
    @Transactional
    public void doTransactionStuffWithAnnotation()
    {
    TransactionAspectSupport.currentTransactionStatus();
    }
    
    public void doTransactionStuffWithoutAnnotation()
    {
    TransactionAspectSupport.currentTransactionStatus();    
    }
}
=========

And the two unit tests :

=========
@Test
public void withJavaAnnotation() // <-- Fails !
{
new MyClass().doTransactionStuffWithAnnotation();
}
@Test(expected = NoTransactionException.class)
public void withoutJavaAnnotation()
{
new MyClass().doTransactionStuffWithoutAnnotation();
}
=========

withJavaAnnotation fails with a NoTransactionException is thrown since that is what TransactionAspectSupport.currentTransactionStatus() throws when the @Transactional method is not weaved.

Here is my pom.xml <build> section:

=========
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<forceAjcCompile>true</forceAjcCompile>
<source>1.6</source>
<target>1.6</target>
<showWeaveInfo>true</showWeaveInfo>
<verbose>true</verbose>
<sources />
<aspectLibraries>
<aspectLibrary>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
</aspectLibrary>
</aspectLibraries>
</configuration>
<executions>
<execution>
<id>compile</id>
<configuration>
<weaveDirectories>
<weaveDirectory>
${project.build.outputDirectory}
</weaveDirectory>
</weaveDirectories>
</configuration>
<phase>process-classes</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<configuration>
<weaveDirectories>
<weaveDirectory>
${project.build.testOutputDirectory}
</weaveDirectory>
</weaveDirectories>
</configuration>
<phase>process-test-classes</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
=========

As you can see, I use aspectj-maven-plugin's "weaveDirectory" with a <sources /> and a <forceAjcCompile>true</forceAjcCompile> to ignore all sources, force compilation despite there being "no sources" and then set the -inpath (via weaveDirectory) to the project's output directories (target/classes and target/test-classes).

I add spring-aspects to the projects aspectpath (via <aspectLibraries>)

Here is the parameter file created by aspectj-maven-plugin

=========
-encoding
UTF-8
-showWeaveInfo
-source
1.6
-target
1.6
-verbose
-classpath
THE_CLASSPATH
-inpath
PATH_TO_PROJECT\test-ctw\target\classes
-aspectpath
PATH_TO_M2REPOSITORY\.m2\repository\org\springframework\spring-aspects\3.2.1.RELEASE\spring-aspects-3.2.1.RELEASE.jar
-d
PATH_TO_PROJECT\test-ctw\target\classes
=========

(I've removed the classpath as it was rather large, let me know if it could be useful)

Note using compile time weaving (not post-compilation weaving) works as expected and load-time weaving works as well (both in Eclipse and Maven). Sadly, these two options cannot be used for this project.

With that information, here are my questions:

- Does the AJDT m2e connector support post-compilation weaving?

- Do I have to add something within the Eclipse project properties, under "AspectJ build" > "Inpath"? (aspectpath is filled with spring-aspects but there is nothing under the Inpath tab)

- What is the recommended configuration to use post-compilation weaving in Eclipse based on a Maven configuration?

- Could I perhaps use a lifecycle mapping to solve my problem?

Thank you very much for your time,
Guillaume Simard

Back to the top