1

I realize there are several similar issues out there, but none of the solutions work for me. I'm building a Spring Boot Java service in an Azure pipeline.

 - task: Maven@3
    displayName: 'Build'
    inputs:
      mavenPomFile: 'pom.xml'
      goals: 'clean org.jacoco:jacoco-maven-plugin:report package'
      publishJUnitResults: true
      codeCoverageToolOption: jacoco
      testResultsFiles: '**/surefire-reports/TEST-*.xml'

I'm getting the following error as I run the build

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project VstsReport: An Ant BuildException has occured: Error while creating report
[ERROR] around Ant part ...<report>... @ 8:11 in /home/vsts/work/1/s/myApp/target/antrun/build-main.xml: Error while analyzing apiservice/target/apiservice-0.0.1-SNAPSHOT.jar@BOOT-INF/lib/log4j-api-2.13.3.jar@org/apache/logging/log4j/util/ProcessIdUtil.class. Can't add different class with same name: org/apache/logging/log4j/util/ProcessIdUtil

I'm attempting to Exclude, but no matter what I put in the Exclude tag, nothing is working. The exclude below do not work. I have tried all permutations I can think of. Even this:

<exclude>**/*.*</exclude>

does absolutely nothing. I must be doing something else wrong.

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.8.4</version>
                <configuration>
                    <excludes>
                        <exclude>../apiservice-0.0.1-SNAPSHOT.jar</exclude>
                    </excludes>
                </configuration>                    
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>                    
                </executions>
            </plugin>   

The plugin seems to acknowledge the exclude statements as they are represented in the log output below.

[INFO] --- jacoco-maven-plugin:0.8.4:prepare-agent (default-prepare-agent-vsts) @ apiservice ---
[INFO] argLine set to -javaagent:/home/vsts/.m2/repository/org/jacoco/org.jacoco.agent/0.8.4/org.jacoco.agent-0.8.4-runtime.jar=destfile=/home/vsts/work/1/s/rulesengine/CCReport43F6D5EF/jacoco.exec,includes=**/*,excludes=../apiservice-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.4:prepare-agent (prepare-agent) @ apiservice ---
[INFO] argLine set to -javaagent:/home/vsts/.m2/repository/org/jacoco/org.jacoco.agent/0.8.4/org.jacoco.agent-0.8.4-runtime.jar=destfile=/home/vsts/work/1/s/rulesengine/CCReport43F6D5EF/jacoco.exec,excludes=../apiservice-0.0.1-SNAPSHOT.jar

UPDATE: Removing

codeCoverageToolOption: jacoco

from the Maven@3 task resolved all the problems. I don't know the purpose of that setting or why it completely overrides any setting in the pom.xml. I'm leaving this post here in case someone finds it useful.

Per
  • 491
  • 6
  • 19
  • The path set in the `exclude` element is relative to the directory `target/classes/`. But the errror message shows the conflict class came from the `log4j-api-2.13.3.jar` in `apiservice-0.0.1-SNAPSHOT.jar` which resided in `target` folder instead of `target/classes/`. Could you have a try setting the exclude path to `../apiservice-0.0.1-SNAPSHOT.jar` – Levi Lu-MSFT Mar 18 '21 at 09:27
  • @LeviLu-MSFT, I updated per your recommendation but still getting the same error. I included the log output above where you can see it looks like the exclude is setup correctly. Any help is greatly appreciated. – Per Mar 26 '21 at 14:40
  • This had nothing to do with jacoco or pom.xml configuration. Removing codeCoverageToolOption: jacoco from the Maven@3 task made everything function as it should. I have no idea what that option does but I wasted a ton of time on it. I'll leave this post here as is in case someone finds it useful – Per Mar 29 '21 at 13:17
  • That's great you fixed it. You can convert above comment to the answer. – Levi Lu-MSFT Mar 30 '21 at 01:51

1 Answers1

1

This had nothing to do with plugin settings, jacoco or exclude paths. Turns out that removing this from the Maven@3 task fixed the issue.

codeCoverageToolOption: jacoco

I don't know the purpose of that setting or why it completely seem to override the pom.xml. I spent way too much time on this, but hopefully this will help someone else.

Per
  • 491
  • 6
  • 19