如何在jenkins中制作jacoco.exec文件

时间:2016-07-13 08:56:41

标签: maven jenkins jacoco

我正在尝试在jenkins + nexus + eclipse中使用jacoco。

但jacoco结果只有0%。

代码下的

是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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.github.myeongjoon</groupId>
  <artifactId>testPage</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>testPage Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- spring dependency -->

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.3.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>

    <!-- jstl -->
    <dependency>
       <groupId>jstl</groupId>
       <artifactId>jstl</artifactId>
       <version>1.2</version>
    </dependency>
    <!-- jstl -->

    <!-- jsp dependency -->
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging-api</artifactId>
        <version>1.1</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet.jsp</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.1</version>
        <scope>provided</scope>
    </dependency>


    <!-- spring dependency -->

    <!-- jacoco report dependency -->


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.maven.wagon</groupId>
        <artifactId>wagon-provider-api</artifactId>
        <version>1.0-alpha-6</version>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.0.4</version>
    </dependency>


    <!-- jacoco dependency -->


    <dependency>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.7.7.201606060606</version>
    </dependency>
    <!-- jacoco dependency -->


  </dependencies>
  <build>
    <finalName>testPage</finalName>


  <!-- jacoco plugin -->


  <plugins>

  <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <argLine>-Denv=local -Dlogback.configurationFile=logger/local-logback.xml</argLine>
                <excludedGroups>int</excludedGroups>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-failsafe-plugin</artifactId>
            <version>2.19.1</version>
            <configuration>
                <!-- property set by jacoco-maven-plugin -->
                <argLine>${itCoverageAgent}</argLine>
                <groups>int</groups>
                <!-- by default only IT*, *IT and *ITCase classes are included -->
                <includes>
                    <include>**/*.java</include>
                </includes>
            </configuration>
            <executions>
                <execution>
                    <id>integration-test</id>
                    <goals>
                        <goal>integration-test</goal>
                        <goal>verify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

                <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <configuration>
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>   

        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.7.201606060606</version>
            <executions>
                <!-- prepare agent for measuring unit tests -->
                <execution>
                    <id>prepare-unit-tests</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <configuration>
                        <destFile>${sonar.jacoco.reportPath}</destFile>
                    </configuration>
                </execution>

                <!-- prepare agent for measuring integration tests -->
                <execution>
                    <id>prepare-integration-tests</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                    <phase>pre-integration-test</phase>
                    <configuration>
                        <destFile>${sonar.jacoco.itReportPath}</destFile>
                        <propertyName>itCoverageAgent</propertyName>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    <!-- 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>








            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.7.201606060606</version>
                <configuration>
                    <fileSets>
                        <fileSet
                                implementation="org.apache.maven.shared.model.fileset.FileSet">
                            <directory>./..</directory>
                            <includes>
                                <include>*.exec</include>
                            </includes>
                        </fileSet>
                    </fileSets>
                    <destFile>jacoco.exec</destFile>

                    <dataFile>jacoco.exec</dataFile>
                </configuration>
            </plugin>
             -->
        </plugins>


  <!-- jacoco plugin -->

  </build>



  <pluginRepositories>
    <pluginRepository>
        <id>KCC_Central</id>
        <url>http://192.168.56.1:8081/repository/KCC_Central/</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
    </pluginRepository>
</pluginRepositories>


</project>

下图是jenkins中的jacoco设置

enter image description here

在代码下是jacoco只返回0%coverag。

enter image description here

我认为jenkins无法生成* .exec文件。

所以后期构建结果只是'找到0 exec文件'。

我该怎么办?

1 个答案:

答案 0 :(得分:0)

我通过将代码添加到catalina.sh

中的tomcat来解决了这个问题

代码:

JAVA_OPT=" -javaagent: {javaagent.jar location}"