问题描述
我意识到有几个类似的问题,但没有一个解决方案适合我。我正在 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 中的任何设置。我把这篇文章留在这里,以防有人觉得它有用。
解决方法
这与插件设置、jacoco 或排除路径无关。事实证明,从 Maven@3 任务中删除它解决了这个问题。
codeCoverageToolOption: jacoco
我不知道该设置的目的或为什么它似乎完全覆盖了 pom.xml。我花了太多时间在这上面,但希望这会对其他人有所帮助。