2

我们有一个多模块 maven 项目,其中 sonar-maven-plugin 和 jacoco maven-plugin 在父 pom 中定义:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>${jacoco.version}</version>
            <configuration>
                <destFile>${sonar.jacoco.reportPath}</destFile>
                <append>true</append>
                <excludes>
                    <exclude>**/generated/**</exclude>
                </excludes>
            </configuration>
            <executions>
                <execution>
                    <id>agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>2.5</version>
        </plugin>

现在我们有一个子模块 common,再次包含其他子模块:

项目结构

在子模块common中,maven结构如下:

<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">
   <parent>
       <groupId>be.groupname</groupId>
       <artifactId>artifactname</artifactId>
       <version>1.0-SNAPSHOT</version>
   </parent>

   <modelVersion>4.0.0</modelVersion>
   <groupId>be.groupname</groupId>
   <artifactId>common-master</artifactId>
   <name>Common - Master</name>
   <packaging>pom</packaging>
   <modules>
       <module>bindings</module>
       <module>core</module>
       <module>tools</module>
   </modules>
</project>

子模块核心具有以下maven结构:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <parent>
        <groupId>be.groupid</groupId>
        <artifactId>common-master</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <artifactId>common-core</artifactId>
    <name>Common - Core</name>
    <packaging>jar</packaging>
    ...
</project>

现在我的问题是,在我的 SonarQube 报告中,我看到了未发现的行:

测试覆盖率

公共主项目包含子模块(公共核心,...)中所有未发现的行。我希望只有公共核心模块会包含这些行。

在文件系统中,我看到在 common/target 文件夹下生成了一个 jacoco.exec。在子目录 common 中,我没有看到正在创建这个文件,而是看到了一个文件 common/core/target/sonar/jacoco-overall.exec

4

0 回答 0