jenkins jacoco

本文介绍如何在Maven项目中使用JaCoCo插件来测量代码覆盖率,并配置Jenkins和SonarQube进行集成,确保代码质量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.pom中加jacoco依赖

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

2.pom的build增加

<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>3.7</version>
                <configuration>
                    <skipEmptyReport>false</skipEmptyReport>
                </configuration>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>0.7.8</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

        </plugins>
    </build>

3.jenkins中POST STEP 选择Execute SonarQube Scanner,Analysis properties中增加下面配置,配置内容有多余的,不过不影响

sonar.projectKey=testjunit
sonar.projectName=testjunit
sonar.projectVersion=1.0
sonar.language=java
sonar.scm.disabled=true  
sonar.projectBaseDir=$WORKSPACE
# src 
sonar.sources=.
sonar.java.source=.
# binDir
sonar.binaries=.
sonar.java.binaries=

sonar.modules=
sonar.sources=src/main/java
sonar.sourceEncoding=UTF-8
sonar.tests=src/test/java
sonar.java.binaries=target
sonar.core.codeCoveragePlugin=jacoco
sonar.jacoco.reportPaths=target/jacoco.exec

 

 

4.构建后操作选择Record JaCoCo coverage report,

 

转载于:https://www.cnblogs.com/paisen/p/8423325.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值