我们正在从 Maven@3 任务迁移到 Maven@4 请参阅此处。这对于大多数存储库都适用,但多模型存储库除外。这给了我以下错误:
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Child module /home/vsts/work/1/s/service/CCReport43F6D5EF of /home/vsts/work/1/s/service/pom.xml does not exist @
@
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[ERROR] Child module /home/vsts/work/1/s/service/CCReport43F6D5EF of /home/vsts/work/1/s/service/pom.xml does not exist @
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:397)
at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:414)
at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:405)
at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:82)
at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:535)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:220)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:963)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:296)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:199)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:569)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
[ERROR] The project nl.XXX:service:1.0.0-SNAPSHOT (/home/vsts/work/1/s/service/pom.xml) has 1 error
[ERROR] Child module /home/vsts/work/1/s/service/CCReport43F6D5EF of /home/vsts/work/1/s/service/pom.xml does not exist
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
##[warning]No code coverage found to publish. There might be a build failure resulting in no code coverage or there might be no tests.
##[error]Build failed
我在天蓝色管道中的任务如下所示
- task: Maven@4
displayName: 'Maven Package'
inputs:
mavenPomFile: 'service/pom.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
jdkArchitectureOption: 'x64'
codeCoverageToolOption: jaCoCo
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'clean package'
isJacocoCoverageReportXML: true
sonarQubeRunAnalysis: true
文件结构如下所示:
project-root/
│
├── service/
│ ├── pom.xml
│ ├── service-impl/
│ │ └── pom.xml
│ └── service-model/
│ └── pom.xml
│
└── azure-pipelines.yml
然后在service-impl pom.xml中有一个core-libraries/pom.xml,其中包含所有存储库的jacoco插件配置。这看起来像下面这样:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<configuration>
<excludes>**/*IT, **/CCReport43F6D5EF/</excludes>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<phase>initialize</phase>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<goals>
<goal>report</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
我注意到从 Maven@3 更改为 Maven@4 时,管道执行的命令略有变化。
来自
/usr/bin/mvn -f /home/vsts/work/1/s/service/pom.xml clean package -Dsonar.jacoco.reportPaths=/home/vsts/work/1/s/service/CCReport43F6D5EF/jacoco.exec -Dsonar.coverage.jacoco.xmlReportPaths=/home/vsts/work/1/s/service/CCReport43F6D5EF/jacoco.xml org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE:sonar
致:
/usr/bin/mvn -f /home/vsts/work/1/s/service/pom.xml clean package org.sonarsource.scanner.maven:sonar-maven-plugin:RELEASE:sonar
因此,reportPaths 和 xmlReportPaths 被删除,这似乎导致了问题。使用 azure 管道中的 options 属性将它们添加回 Maven 任务似乎并没有解决问题。请注意,在 sonarcloud 中,我们收到此似乎相关的错误消息:
Property 'sonar.jacoco.reportPaths' is no longer supported. Use JaCoCo's xml report and sonar-jacoco plugin.
我在互联网上搜索了很多,Maven@3 似乎也出现了这个问题,但对我们来说这仍然有效。现在,自从我们迁移到 Maven@4 后,它就崩溃了。我在上面发现了什么:
确保您已指定 #codeCoverageClassFilesDirectories 和 #codeCoverageSourceDirectories 作为任务输入。这两个参数对于单模块项目是可选的,但对于多模块项目是必需的。
我不清楚发生了什么以及应该如何解决/解决这个问题。我想知道是否有人有想法。预先感谢
我通过实际使用这里提到的这个解决方法设法回答了我自己的问题。
- task: Maven@4
displayName: 'Maven Package with Code Coverage'
inputs:
mavenPomFile: 'service/pom.xml' # Parent POM file
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
jdkArchitectureOption: 'x64'
mavenVersionOption: 'Default'
codeCoverageToolOption: 'None'
sonarQubeRunAnalysis: true
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<configuration>
<excludes>**/*IT</excludes>
</configuration>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<goals>
<goal>report</goal>
</goals>
<phase>test</phase>
<configuration>
<formats>
<format>XML</format>
</formats>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<goals>
<goal>report</goal>
</goals>
<phase>test</phase>
</execution>
</executions>
</plugin>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.awesome-app.pipeline</groupId>
<artifactId>code-coverage-merge</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Awesome App Code Coverage Merge</name>
<description>Merge Code Coverage from all modules</description>
<properties>
<maven.install.skip>true</maven.install.skip>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<echo message="Generating JaCoCo Reports" />
<taskdef name="report" classname="org.jacoco.ant.ReportTask">
<classpath path="{basedir}/target/jacoco-jars/org.jacoco.ant.jar" />
</taskdef>
<report>
<executiondata>
<file file="${project.basedir}/service-impl/target/jacoco.exec" />
</executiondata>
<structure name="Jacoco report">
<group name="service-impl">
<classfiles>
<fileset dir="${project.basedir}/service-impl/target/classes" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${project.basedir}/service-impl/src/main/java" />
</sourcefiles>
</group>
<group name="service-model">
<classfiles>
<fileset dir="${project.basedir}/service-model/target/classes" />
</classfiles>
</group>
</structure>
<html destdir="${project.build.directory}/site/jacoco" />
<xml destfile="${project.build.directory}/site/jacoco/jacoco.xml" />
<csv destfile="${project.build.directory}/site/jacoco/jacoco.csv" />
</report>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>0.8.7</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
- task: SonarCloudPublish@2
inputs:
pollingTimeoutSec: '300'
- task: Maven@4
displayName: 'Run code coverage maven'
inputs:
mavenPomFile: 'service/aggregator-pom.xml'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
jdkArchitectureOption: 'x64'
mavenVersionOption: 'Default'
- task: PublishCodeCoverageResults@2
inputs:
summaryFileLocation: $(System.DefaultWorkingDirectory)/service/target/site/jacoco/jacoco.xml
pathToSources: $(System.DefaultWorkingDirectory)/service
完成所有这些后就可以了。我只注意到新任务中 CodeCoverage 的 UI 发生了变化(与解决方法示例相比,我使用 @2 而不是 @1)。问题是新用户界面缺少一些功能。有些人也提到了这个问题here,但微软似乎并不打算修复它。到目前为止,我们使用 sonarcloud 代码覆盖率,除了这个麻烦之外,这似乎不是太大的问题。