我意识到那里有几个类似的问题,但没有一个解决方案适合我。我正在 Azure 管道中构建 Spring Boot Java 服务。
- 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'
运行构建时出现以下错误
[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
我正在尝试排除,但无论我在排除标签中放了什么,都没有任何效果。下面的排除不起作用。我已经尝试了所有我能想到的排列方式。即使这样:
<exclude>**/*.*</exclude>
绝对什么都不做。我一定做错了什么。
<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>
该插件似乎承认排除语句,因为它们在下面的日志输出中表示。
[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
更新:删除
codeCoverageToolOption: jacoco
来自 Maven@3 任务解决了所有问题。我不知道该设置的目的或为什么它完全覆盖 pom.xml 中的任何设置。我把这篇文章留在这里,以防有人觉得它有用。