저는 Maven 프로젝트로 Jenkins Sonar 설정을했습니다. 이 maven 프로젝트에는 하나의 pom이 있지만 java, javascript, html 등이 있습니다. 따라서 sonar의 경우 다중 모듈 프로젝트이므로 각 파트에 대한 통계를 얻을 수 있습니다.유닛 테스트 커버리지가 누락되었지만 유닛 테스트 통계가 있습니다.
우리는 또한 프로젝트를위한 코드 커버리지 분석을 원합니다. 즉, 우리는 소나 분석 전에 테스트를 실행하고 내보낼 필요가 있다는 것을 의미합니다. (적어도 소나 러너가 수집 한 것에서이 유형을 수행 할 수는 없습니다. anaysis).
그래서 난 내 젠킨스 작업이 첫 단계로 clean package
을 수행하도록 설정해야하고 우리는 우리가 두 번째 단계로 호출 독립 수중 음파 탐지기 분석을 추가 실행합니다. 모든 다양한 설정을 사용하여 프로젝트의 루트에 sonar-project.properties 파일이 있습니다. 여기있다 : 나는 mvn clean package
을 수행 할 때 로컬로 모든 실행, 그리고 내가 갈 수있는 그래서
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
<!-- Skips unit tests if the value of skip.unit.tests property is true -->
<!--<skipTests>${skip.unit.tests}</skipTests>-->
<!-- Excludes integration tests when unit tests are run. -->
<excludes>
<exclude>**/IT*.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.6.4.201312101107</version>
<executions>
<!--
Prepares the property pointing to the JaCoCo runtime agent which
is passed as VM argument when Maven the Surefire plugin is executed.
-->
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
<!--
Sets the name of the property containing the settings
for JaCoCo runtime agent.
-->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<!--
Ensures that the code coverage report for unit tests is created after
unit tests have been run.
-->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
<!-- Sets the output directory for the code coverage report. -->
<outputDirectory>${project.build.directory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
:
sonar.projectKey=Project
sonar.projectName=Project
sonar.projectVersion=0.2.0-SNAPSHOT
sonar.projectDescription=Super Project
sonar.modules=project-java,project-web,project-js
project-java.sonar.dynamicAnalysis=reuseReports
project-java.sonar.core.codeCoveragePlugin=jacoco
project-java.sonar.dynamicAnalysis=reuseReports
project-java.sonar.junit.reportsPath=target/surefire-reports
project-java.sonar.jacoco.reportPath=target/coverage-reports/jacoco-ut.exec
project-java.sonar.projectName=project-java
project-java.sonar.language=java
project-java.sonar.projectBaseDir=.
project-java.sonar.sources=src/main/java
project-java.sonar.java.source=1.7
project-web.sonar.projectName=project-web
project-web.sonar.language=web
project-web.sonar.projectBaseDir=.
project-web.sonar.sources=src/main/webapp/partials
project-js.sonar.projectName=project-js
project-js.sonar.language=js
project-js.sonar.projectBaseDir=.
project-js.sonar.sources=src/main/webapp/js
지금 내 치어에서 나는 (대부분의 경우
Creating Code Coverage Reports for Unit And Integration Tests with The JaCoCo Maven Plugin에서 함께 따라) 다음을 추가 대상 디렉토리에 생성 된 보고서를 봅니다. 음파 탐지기는 이것을 사용하지 않지만 코드 커버리지 정보를 가지고 있습니다. 이제 소나 작업은 모든 것이 잘 작동하는 것 같다 실행되지만 결과는 단위 테스트 커버리지 번호를 누락하는 경우 : 내가 본
14:39:43.929 INFO - Sensor JaCoCoSensor...
14:39:43.932 INFO - Project coverage is set to 0% since there is no directories with classes.
14:39:43.932 INFO - Sensor JaCoCoSensor done: 3 ms
: 내가 찾은 빌드 로그를 찾고
을 “Project coverage is set to 0%” – JaCoCo and Sonar in Jenkins, 그리고 거기에 아무 소용이 제안을 시도. 그래서 나는 다른 설정을 놓치고 있거나 뭔가 잘못 설정했다고 가정합니다.
거의 동시에 게시해야합니다. 어쨌든, 컴파일 된 클래스 파일의 위치를 jacoco에 알려주는 속성이 누락되었습니다. 어쨌든 그 것을 놓쳤거나 전에 제가 경험했던 모든 예에서 지식이 추측되었습니다. 생각해 줘서 고마워. –