关于使用Maven在Azure DevOps中构建多模块项目的Jacoco代码覆盖问题

问题描述 投票:2回答:1

在Azure Devops Maven构建管道中,在构建多模块Java项目时,构建成功。

但是,Jacoco代码覆盖范围失败,出现以下错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (default) on project VstsReport: An Ant BuildException has occured: Unable to read execution data file /vsts/agent/_work/8/s/CCReport43F6D5EF/jacoco.exec
2020-01-02T22:17:12.5100407Z [ERROR] around Ant part ...... @ 8:11 in /vsts/agent/_work/8/s/target/antrun/build-main.xml: /vsts/agent/_work/8/s/CCReport43F6D5EF/jacoco.exec (No such file or directory)

Azure管道yml文件具有以下任务参数:

task: Maven@3
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/TEST-*.xml'
goals: 'package'
options: '--settings settings.xml'
codeCoverageToolOption: JaCoCo
codeCoverageSourceDirectories: epubcheck-service/src/main,epubcheck-service/src/test
codeCoverageClassFilesDirectories: epubcheck-service/target/classes,epubcheck-service/target/test-classes
sonarQubeRunAnalysis: true

如果我注释了codeCoverage参数,则Maven构建任务将成功完成。仅当我在多模块项目上添加codeCoverage参数时,才会出现上述错误。

使用Azure DevOps管道构建Java maven构建和Jacoco代码覆盖率工具的人可以帮助我吗?

maven azure-devops jacoco
1个回答
0
投票

在父项目的pom.xml中包括jacoco-maven-plugin为我们解决了它。以下是摘录:

<plugin>
    <groupId>org.sonarsource.scanner.maven</groupId>
    <artifactId>sonar-maven-plugin</artifactId>
</plugin> 
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>
© www.soinside.com 2019 - 2024. All rights reserved.