clover instrumentation exclusion on maven
Asked by will zhang:

Hi,

I'm having following error while using clover on my project. It seems clover added lines into a supposed to be empty method. So I'm using this exclusion configuration to excluse all java source that are having "Aspect" in it's name. However, the exclusion seems not working. I can still see the error while compiling.

Any idea why?

I know commenting out on source file using "///CLOVER: OFF" can turn off instrumentation on certain method lines. However I have so many files that I need to add these lines in. So exclusion on file pattern would work better in this case.  

Error messages from Maven:

```
[INFO] --- aspectj-maven-plugin:1.7:compile (default) @ internal-framework ---[INFO] Showing AJC message detail for messages of types: [error, warning, fail][ERROR] Pointcuts without an if() expression should have an empty method body           /home/willz/git/nsx/mp/proton/internal-framework/target/clover/src-instrumented/com/vmware/nsx/management/idempotency/service/IdempotencyAspect.java:52private void executionOfIdempotentAnnotatedMethod(Idempotent idempotent) {try{__CLR4_1_1je1je1isgiwyie.R.inc(25129);[WARNING] no match for this type name: com.vmware.nsx.management.container.dao.impl.GemFireTransactionHandler [Xlint:invalidAbsoluteTypeName]           /home/willz/git/nsx/mp/proton/internal-framework/target/clover/src-instrumented/com/vmware/nsx/management/container/aspects/TransactionAspectSupport.java:32@Pointcut(value = " execution(* *(..))  &amp;&amp; !within(com.vmware.nsx.management.container.dao.impl.GemFireTransactionHandler)")                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^[ERROR] Pointcuts without an if() expression should have an empty method body           /home/willz/git/nsx/mp/proton/internal-framework/target/clover/src-instrumented/com/vmware/nsx/management/container/aspects/TransactionAspectSupport.java:33private void anyMethodOutsideThisAspect() {try{__CLR4_1_1fbffbfisgiww3n.R.inc(19853);[ERROR] Pointcuts without an if() expression should have an empty method body           /home/willz/git/nsx/mp/proton/internal-framework/target/clover/src-instrumented/com/vmware/nsx/management/container/aspects/TransactionAspectSupport.java:43private void executionOfAnyPublicMethodTransactionalType() {try{__CLR4_1_1fbffbfisgiww3n.R.inc(19854);[ERROR] Pointcuts without an if() expression should have an empty method body           /home/willz/git/nsx/mp/proton/internal-framework/target/clover/src-instrumented/com/vmware/nsx/management/container/aspects/TransactionAspectSupport.java:51private void executionOfTransactionalMethod() {try{__CLR4_1_1fbffbfisgiww3n.R.inc(19855);[ERROR] Pointcuts without an if() expression should have an empty method body           /home/willz/git/nsx/mp/proton/internal-framework/target/clover/src-instrumented/com/vmware/nsx/management/container/aspects/TransactionAspectSupport.java:62protected void transactionalMethodExecution(Object txObject) {try{__CLR4_1_1fbffbfisgiww3n.R.inc(19856);[ERROR] Pointcuts without an if() expression should have an empty method body           /home/willz/git/nsx/mp/proton/internal-framework/target/clover/src-instrumented/com/vmware/nsx/management/container/aspects/TransactionalCheckerAspect.java:24public void annotatedWithTransactional() {try{__CLR4_1_1fblfblisgiww44.R.inc(19857);
```

Pom.xml:

```
&lt;plugin&gt;    &lt;groupId&gt;com.atlassian.maven.plugins&lt;/groupId&gt;    &lt;artifactId&gt;clover-maven-plugin&lt;/artifactId&gt;    &lt;version&gt;4.1.1&lt;/version&gt;    &lt;configuration&gt;    ...    &lt;excludes&gt;        &lt;exclude&gt;**/*test/java&lt;/exclude&gt;        &lt;exclude&gt;**/*Test.groovy&lt;/exclude&gt;        &lt;exclude&gt;**/*Aspect.java&lt;/exclude&gt;        &lt;exclude&gt;**/*Aspect*.java&lt;/exclude&gt;        &lt;exclude&gt;**/TransactionalCheckerAspect.java&lt;/exclude&gt;    &lt;/excludes&gt;&lt;/configuration&gt;
```


Answers:
author: Marek Parfianowicz
body: Hi Will,

Unfortunately using ///CLOVER:OFF and ///CLOVER:ON is the only way to disable Clover instrumentation on methods.

The [methodContexts](https://docs.atlassian.com/clover-maven-plugin/latest/setup-mojo.html#methodContexts) filter, which is based on method's signature, will not work in this case, because it does **not** stop instrumenting the method (the method context filter adds a special marker in Clover's database, so that such method can be later excluded in reports).

Alternatively, you could experiment with the Clover AspectJ Compiler plugin - <https://confluence.atlassian.com/display/CLOVER/Clover+AspectJ+Compiler> - keep in mind however, that this plugin is not officially supported.

comments: author: Marek Parfianowicz
body: <https://answers.atlassian.com/questions/294911>


Tags: clover

clover-maven-plugin