1

我有 Java/Maven 开源项目,涵盖了 sonarcloud。我的 CI/CD 是 Travis-ci,我的代码源是 Github。

https://github.com/NoraUi/NoraUi

在 2020 年 12 月 18 日之前,我的 surfire 和 jacoco 配置还可以,但是在 sonarcloud 更改之后,我的项目的代码覆盖率不起作用。

我的 pom.xml:https ://github.com/NoraUi/NoraUi/blob/master/pom.xml

<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<jacoco-maven-plugin.version>0.8.5</jacoco-maven-plugin.version>
<sonar-maven-plugin.version>3.7.0.1746</sonar-maven-plugin.version>
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<sonar.sources>${project.basedir}/src/main/java/</sonar.sources>
<sonar.junit.reportPaths>${project.build.directory}/surefire-reports/junit</sonar.junit.reportPaths>
<sonar.surefire.reportPaths>${project.build.directory}/surefire-reports</sonar.surefire.reportPaths>
<sonar.jacoco.directory>${project.testresult.directory}/coverage/jacoco</sonar.jacoco.directory>
<sonar.jacoco.reportPath>${sonar.jacoco.directory}/jacoco.exec</sonar.jacoco.reportPath>
<sonar.tests>${project.basedir}/src/test/</sonar.tests>
<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
<sonar.exclusions>**/cucumber/**/*,**/*Exception.*,**/annotation/**/*,**/noraui/model/**/*,**/noraui/data/rest/Row.java,**/noraui/utils/Constants.java,**/noraui/application/steps/MailSteps.java</sonar.exclusions>
<sonar.test.exclusions>**/*.css</sonar.test.exclusions>

<profile>
        <id>unit-tests</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.jacoco</groupId>
                    <artifactId>jacoco-maven-plugin</artifactId>
                    <version>${jacoco-maven-plugin.version}</version>
                    <executions>
                        <execution>
                            <id>pre-unit-tests</id>
                            <phase>compile</phase>
                            <goals>
                                <goal>prepare-agent</goal>
                            </goals>
                            <configuration>
                                <destFile>${sonar.jacoco.reportPath}</destFile>
                                <propertyName>surefireArgLine</propertyName>
                            </configuration>
                        </execution>
                        <execution>
                            <id>post-unit-test</id>
                            <phase>test</phase>
                            <goals>
                                <goal>report</goal>
                            </goals>
                            <configuration>
                                <dataFile>${sonar.jacoco.reportPath}</dataFile>
                                <outputDirectory>${sonar.jacoco.directory}</outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>${maven-surefire-plugin.version}</version>
                    <configuration>
                        <systemPropertyVariables>
                            <resourcespath>${ciToolResourcesPath}</resourcespath>
                            <cucumber.options>${cucumber.options}</cucumber.options>
                            <webdriver.ie.driver>src/test/resources/drivers/%s/internetexplorer/%s/IEDriverServer%s</webdriver.ie.driver>
                            <webdriver.chrome.driver>src/test/resources/drivers/%s/googlechrome/%s/chromedriver%s</webdriver.chrome.driver>
                            <webdriver.gecko.driver>src/test/resources/drivers/%s/firefox/%s/geckodriver%s</webdriver.gecko.driver>
                            <SpeedRegulator.annotation.enable>false</SpeedRegulator.annotation.enable>
                            <SpeedRegulators.annotation.enable>false</SpeedRegulators.annotation.enable>
                            <Time.annotation.enable>false</Time.annotation.enable>
                            <Times.annotation.enable>false</Times.annotation.enable>
                            <uid>${uid}</uid>
                            <password>${password}</password>
                            <cookie>${cookie}</cookie>
                            <role>${role}</role>
                        </systemPropertyVariables>
                        <includes>
                            <include>**/*UT.java</include>
                            <include>**/Runner.java</include>
                        </includes>
                        <argLine>-Dfile.encoding=UTF-8 ${surefireArgLine}</argLine>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>${sonar-maven-plugin.version}</version>
                </plugin>
            </plugins>
        </build>
    </profile>

我尝试多次更改但不再工作。

我尝试添加这个:

sonar.coverage.jacoco.xmlReportPaths=target/site/jacoco/jacoco.xml
4

0 回答 0