Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Maven jenkins构建作业之后,SonarQube中的测试覆盖率始终为空_Maven_Jenkins_Sonarqube_Jacoco Maven Plugin - Fatal编程技术网

Maven jenkins构建作业之后,SonarQube中的测试覆盖率始终为空

Maven jenkins构建作业之后,SonarQube中的测试覆盖率始终为空,maven,jenkins,sonarqube,jacoco-maven-plugin,Maven,Jenkins,Sonarqube,Jacoco Maven Plugin,我使用的是最新的SonarQube 6.4,Jenkins 2.60.1,我有一个应用程序进行了一些测试。使用覆盖率插件在eclipse中运行应用程序后,我可以看到大约90%的测试覆盖率。当我使用Jenkins构建我的应用程序,然后SonarQube显示结果时,我的问题就开始了,但是测试覆盖率总是为空。我相信我错过了一些东西,所以任何帮助都将被感激 这是我的pom.xml文件: <project xmlns="http://maven.apache.org/POM/4.0.0" x

我使用的是最新的SonarQube 6.4,Jenkins 2.60.1,我有一个应用程序进行了一些测试。使用覆盖率插件在eclipse中运行应用程序后,我可以看到大约90%的测试覆盖率。当我使用Jenkins构建我的应用程序,然后SonarQube显示结果时,我的问题就开始了,但是测试覆盖率总是为空。我相信我错过了一些东西,所以任何帮助都将被感激

这是我的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>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.4.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <sonar.host.url>http://localhost:9000</sonar.host.url>
    <sonar.sources>src/main</sonar.sources>
    <sonar.tests>src/test</sonar.tests>
    <!-- Below property indicates the pattern of the test suite -->
    <runSuite>**/*Suite.class</runSuite>
    <!-- Sonar-JaCoCo properties -->
    <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
    <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
    <sonar.jacoco.reportPaths>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPaths>
    <sonar.language>java</sonar.language>
    <jacoco.out.path>${session.executionRootDirectory}/target</jacoco.out.path>
    <sonar.jacoco.itReportPath>${env.WORKSPACE}/target/${jacoco.out.file}</sonar.jacoco.itReportPath>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>

    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.0</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.dbunit/dbunit -->
    <dependency>
        <groupId>org.dbunit</groupId>
        <artifactId>dbunit</artifactId>
        <version>2.5.3</version>
    </dependency>


    <dependency>
        <groupId>com.github.springtestdbunit</groupId>
        <artifactId>spring-test-dbunit</artifactId>
        <version>1.3.0</version>
    </dependency>

    <!-- Adds Tomcat and Spring MVC, along others, jackson-databind included 
        transitively -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>


    <dependency>
        <groupId>com.fasterxml.jackson.dataformat</groupId>
        <artifactId>jackson-dataformat-xml</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.jayway.restassured/spring-mock-mvc -->
    <dependency>
        <groupId>com.jayway.restassured</groupId>
        <artifactId>spring-mock-mvc</artifactId>
        <version>2.9.0</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-mongodb</artifactId>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.lordofthejars/nosqlunit-core -->
    <dependency>
        <groupId>com.lordofthejars</groupId>
        <artifactId>nosqlunit-core</artifactId>
        <version>1.0.0-rc.5</version>
    </dependency>


</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <reportsDirectory>${project.build.directory}/target/surefire-reports</reportsDirectory>
                <argLine>${jacoco.agent.argLine}</argLine>
            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-failsafe-plugin</artifactId>
            <executions>
                <execution>
                    <id>verify</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                    <configuration>
                        <argLine>${jacoco.agent.arg}</argLine>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <!-- Below plugin ensures the execution of test cases during maven build -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <configuration>
                <includes>
                    <include>${runSuite}</include>
                </includes>
            </configuration>
        </plugin>
        <!-- Sonar-JaCoCo integration plugin -->
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.9</version>
            <configuration>
                <destFile>${sonar.jacoco.reportPaths}</destFile>
                <append>true</append>
            </configuration>
            <executions>
                <execution>
                    <id>agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>
我使用的最后一个命令是:

    clean org.jacoco:jacoco-maven-plugin:prepare-agent install -P 
    integration-tests --fail-at-end

如果您需要我的配置的任何其他内容,我将在此处发布。

后期生成操作已被弃用

您的是一个Maven项目,因此不需要显式提供属性


,在生成命令之后,您真正需要做的是:
$SONAR\u MAVEN\u GOAL-Dsonar.host.url=$SONAR\u host\u url

提供与Jenkins中控制台输出的覆盖率相关的日志谢谢,它帮助我了解了如何正确运行它。我还改变了一些属性,最后它成功了。
    clean org.jacoco:jacoco-maven-plugin:prepare-agent install -P 
    integration-tests --fail-at-end