我们已升级到Sonar 4.5.2,现在无法使用Bamboo和Maven从Cobertura获得单元测试覆盖率数据。

我发现我需要添加
cobertura:cobertura -Dcobertura.report.format=xml
到Maven build命令,但是在Bamboo构建之后,添加的内容仍然无法显示Sonar 4.5.2中的单元测试范围。在pom.xmlmvn sonar:sonar命令中我还需要做其他事情吗?声纳配置有什么变化吗?

因此,我正在跑步:

mvn clean cobertura:cobertura -Dcobertura.report.format=xml install
mvn sonar:sonar


我是该项目,语言,工具的新手,所以详细的答案将不胜感激。 (也就是说,不要只是说添加此标签,请告诉我pom中的位置。谢谢。)

pom.xml已附加。我不确定需要什么部分,所以我包括了所有非公司专有的内容。

<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>
<parent>
    <groupId>com.mycompany.commons</groupId>
    <artifactId>mycompany-commons-pom</artifactId>
    <version>3.0</version>
    <relativePath />
</parent>
<groupId>com.mycompany.myproj</groupId>
<artifactId>main</artifactId>
<version>3.1.0.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Main</name>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <!-- display system information to aid in debugging -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-help-plugin</artifactId>
            <!-- only the parent should do this -->
            <inherited>false</inherited>
            <executions>
                <execution>
                    <id>displayInfo</id>
                    <goals>
                        <goal>system</goal>
                    </goals>
                    <phase>validate</phase>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-enforcer-plugin</artifactId>
            <executions>
                <execution>
                    <id>enforce-versions</id>
                    <goals>
                        <goal>enforce</goal>
                    </goals>
                    <configuration>
                        <rules>
                            <requireMavenVersion>
                                <version>[3.0,)</version>
                            </requireMavenVersion>
                        </rules>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <configuration>
                <tagBase>https://svn.forge.mycompany.com/svnroot/myproj/tags/platform</tagBase>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <argLine>-Xmx3072m -XX:MaxPermSize=512m -XX:-UseSplitVerifier</argLine>
    </configuration>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>regex-property</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>regex-property</goal>
                    </goals>
                    <configuration>
                        <name>main.pom.project.version.no.snapshot</name>
                        <value>${project.version}</value>
                        <regex>(.*)-SNAPSHOT</regex>
                        <replacement>$1</replacement>
                        <failIfNoMatch>false</failIfNoMatch>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <extensions>
        <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-webdav</artifactId>
            <version>1.0-beta-2</version>
        </extension>
        <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-ssh</artifactId>
            <version>2.0</version>
        </extension>
    </extensions>

    <pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <descriptor>src/main/assembly/dist.xml</descriptor>
                    <appendAssemblyId>false</appendAssemblyId>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-clean-plugin</artifactId>
                <version>2.6</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.9.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.3.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-help-plugin</artifactId>
                <version>2.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.5</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.5.1</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.17</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9.1</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>rpm-maven-plugin</artifactId>
                <version>2.0.1</version>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>xml-maven-plugin</artifactId>
                <version>1.0</version>
            </plugin>

            <!-- This is only for m2eclipse interoperability. It breaks if not defined in the top level pom (https://bugs.eclipse.org/bugs/show_bug.cgi?id=371618#c1) -->
            <plugin>
                <artifactId>lifecycle-mapping</artifactId>
                <groupId>org.eclipse.m2e</groupId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>

                            <!-- Ignore for eclipse build -->
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <artifactId>maven-dependency-plugin</artifactId>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>unpack</goal>
                                        <goal>unpack-dependencies</goal>
                                        <goal>copy-dependencies</goal>
                                        <goal>copy</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>

                            <!-- Ignore for eclipse build -->
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <artifactId>maven-ear-plugin</artifactId>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>generate-application-xml</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>

                            <!-- Ignore for eclipse build -->
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <artifactId>maven-antrun-plugin</artifactId>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>run</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>

                            <!-- Ignore for eclipse build -->
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>rpm-maven-plugin</artifactId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>rpm</goal>
                                        <goal>version</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>

                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>jaxb2-maven-plugin</artifactId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>xjc</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-enforcer-plugin</artifactId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>enforce</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.codehaus.mojo</groupId>
                                    <artifactId>build-helper-maven-plugin</artifactId>
                                    <versionRange>[1.0,)</versionRange>
                                    <goals>
                                        <goal>regex-property</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

</build>
<dependencyManagement>
    <dependencies>

        <!-- -->
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>6.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.gigaspaces</groupId>
            <artifactId>gs-runtime</artifactId>
            <version>10.1.0-ga-b12600</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.gigaspaces</groupId>
            <artifactId>gs-openspaces</artifactId>
            <version>10.1.0-ga-b12600</version>
            <scope>provided</scope>
        </dependency>

        <!-- Unit Testing -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymock</artifactId>
            <version>3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.easymock</groupId>
            <artifactId>easymockclassextension</artifactId>
            <version>3.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>${mockito.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.ibm.websphere.appserver</groupId>
            <artifactId>was_public</artifactId>
            <version>8.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.ibm.ws.sip</groupId>
            <artifactId>interface</artifactId>
            <version>7.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.5</version>
            <scope>provided</scope>
        </dependency>

        <!-- JBOSS 6.1 -->
        <dependency>
            <!-- EJB 3.1 Spec (JBoss 6.1) -->
            <groupId>org.jboss.spec.javax.ejb</groupId>
            <artifactId>jboss-ejb-api_3.1_spec</artifactId>
            <version>1.0.2.Final</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.ejb</groupId>
            <artifactId>ejb-api</artifactId>
            <version>3.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>com.springsource.org.apache.commons.pool</artifactId>
            <version>1.5.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>com.springsource.org.apache.commons.dbcp</artifactId>
            <version>1.2.2.osgi</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.openjpa</groupId>
            <artifactId>openjpa-persistence</artifactId>
            <version>2.2.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- -->
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-module-junit4</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.powermock</groupId>
            <artifactId>powermock-api-mockito</artifactId>
            <version>${powermock.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>13.0.1</version>
        </dependency>
        <dependency>
            <groupId>findbugs</groupId>
            <artifactId>findbugs</artifactId>
            <version>1.0.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.findbugs</groupId>
            <artifactId>findbugs</artifactId>
            <version>2.0.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.9.8</version>
        </dependency>
        <dependency>
            <groupId>apache-log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.media</groupId>
            <artifactId>mscontrol</artifactId>
            <version>1.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- common connector dependencies -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.2</version>
        </dependency>

    </dependencies>
</dependencyManagement>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

    <powermock.version>1.5.4</powermock.version>
    <mockito.version>1.9.5</mockito.version>
    <WAS.version>8.0.0.6</WAS.version>

    <!-- GigaSpaces -->
    <gigaspaces-version>10.1.0-ga-b12600</gigaspaces-version>
    <springframework-version>4.1.5.RELEASE</springframework-version>
</properties>
<modules>
    <module>common</module>
    <module>api</module>
    <module>sdk</module>
    <module>platform</module>
    <module>services</module>
    <module>webrtc</module>
</modules>

<profiles>
    <!-- for use with Sonar dev-env is reset by the build to go somewhere else -->
    <profile>
        <id>dev-env</id>
        <activation>
            <property>
                <name>!official.build</name>
            </property>
        </activation>
        <properties>
            <sonar.jdbc.url>jdbc:h2:tcp://localhost:9092/sonar;create=true</sonar.jdbc.url>
            <sonar.jdbc.driver>org.h2.Driver</sonar.jdbc.driver>
            <sonar.jdbc.username>sonar</sonar.jdbc.username>
            <sonar.jdbc.password>sonar</sonar.jdbc.password>
            <sonar.host.url>http://localhost:9000</sonar.host.url>
            <sonar.language>java</sonar.language>
        </properties>
    </profile>
    <profile>
        <!-- Used for the nightly sonar build... basically just adds element manager -->
        <id>sonar</id>
        <modules>
            <module>elementmgr</module>
        </modules>
        <properties>
            <sonar.core.codeCoveragePlugin>cobertura</sonar.core.codeCoveragePlugin>
            <sonar.java.coveragePlugin>cobertura</sonar.java.coveragePlugin>
            <sonar.cobertura.reportPath>target/site/cobertura/coverage.xml</sonar.cobertura.reportPath>
            <sonar.language>java</sonar.language>
            <sonar.skippedModules>
                archive-jaxb,test,unit-test-utils,ExcludeDoclet
            </sonar.skippedModules>
        </properties>
    </profile>
</profiles>

最佳答案

为了获得cobertura的覆盖范围信息,我的同事禁止Bamboo寻求测试结果。据他说,Bamboo对测试结果的分析干扰了cobertura的结果。

我还将注意到,在我们的两个项目之一中,我们必须将cobertura:cobertura成为Bamboo构建的一个单独步骤,在install和sonar:sonar之间进行;在另一个项目中,我们必须将其与安装步骤结合起来,因为“其中的软件包具有解包依赖性,cobertura并没有将其解包为独立任务。”

关于java - 如何使用Maven和Bamboo在Sonar 4.5.2中获得Cobertura的覆盖率?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29480248/

10-11 17:53