I have projects created using aspectj-maven-plugin to compile and use cobertura-maven-plugin to cover code. For compilation over time, this works fine at startup mvn site, although the tests are compiled / executed twice to allow Cobertura weaving.
Running mvn sitewith the configuration below leads to the following output:
[INFO] Preparing surefire-report:report
[INFO] [aspectj:compile {execution: compile_with_aspectj}]
...
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
...
[INFO] [compiler:testCompile {execution: test-compile}]
[INFO] Compiling 8 source files to C:\test\aop-test
[INFO] [aspectj:test-compile {execution: test-compile_with_aspectj}]
...
[INFO] [surefire:test]
...
[INFO] Preparing cobertura:cobertura
[INFO] [aspectj:compile {execution: compile_with_aspectj}]
...
[INFO] [compiler:compile]
[INFO] Nothing to compile - all classes are up to date
[INFO] [cobertura:instrument]
[INFO] Cobertura 1.8 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
Instrumenting 11 files to C:\test\aop-test\generated-classes\cobertura
Cobertura: Saved information on 11 classes.
Instrument time: 250ms
[INFO] Instrumentation was successful.
[INFO] [compiler:testCompile {execution: test-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [aspectj:test-compile {execution: test-compile_with_aspectj}]
...
[INFO] [surefire:test]
...
Cobertura: Coverage data file C:\test\aop-test\cobertura.ser either
does not exist or is not readable. Creating a new data file.
Cobertura: Saved information on 8 classes.
My configuration is below.
Cobertura , - java, .
, :
before(Throwable e, Object subject): handlers(e, subject) {
Log logger = getTraceLog(subject.getClass());
...
}
Java-, :
before(Throwable e, Object subject): handlers(e, subject) {
Log logger = getTraceLog(subject.getClass());
//get helper type and delegate processing to that type.
getFormatterHelper().traceErrorHandling(logger, thisJoinPoint, e);
}
aspectj cobertura:
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>compile_with_aspectj</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<complianceLevel>1.5</complianceLevel>
</configuration>
</execution>
<execution>
<id>test-compile_with_aspectj</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<complianceLevel>1.5</complianceLevel>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjtools</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
<reporting>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
<outputDirectory>target/site/cobertura</outputDirectory>
</configuration>
</plugin>
<plugins
</reporting>