2014-01-29 4 views
2

저는 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 

: 내가 찾은 빌드 로그를 찾고

Sample Output

“Project coverage is set to 0%” – JaCoCo and Sonar in Jenkins, 그리고 거기에 아무 소용이 제안을 시도. 그래서 나는 다른 설정을 놓치고 있거나 뭔가 잘못 설정했다고 가정합니다.

답변

3

sonar.binaries이라는 속성이 누락되었습니다. 그래서 나는 속성 파일에

project-java.sonar.binaries=target/classes 

줄을 추가했고 트릭을했습니다.

1

시도해 볼 수 있습니까 mvn 새로 설치?

+0

거의 동시에 게시해야합니다. 어쨌든, 컴파일 된 클래스 파일의 위치를 ​​jacoco에 알려주는 속성이 누락되었습니다. 어쨌든 그 것을 놓쳤거나 전에 제가 경험했던 모든 예에서 지식이 추측되었습니다. 생각해 줘서 고마워. –

0

동일한 문제가 있습니다. 적용 범위가 없습니다.

그러나 내 프로젝트에서는 org.jacoco : jacoco-maven-plugin : prepare-agent를 내 Maven 빌드에 추가하는 것으로 충분합니다.

난 그냥 전화 1and (수중 음파 탐지기는 젠킨스와 동일한 시스템에서 실행되는) 어떤 수중 음파 탐지기와 jacoco 구성이 필요하지 않습니다 그 수중 음파 탐지기는 젠킨스 수중 음파 탐지기를 통해 포스트 빌드 작용에 의해 호출

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

후 플러그인. http://docs.codehaus.org/display/SONAR/Configuring+SonarQube+Jenkins+Plugin

버전 :

젠킨스 1.583 소나 플러그인 2.1

PS pom에 플러그인 버전이 구성되었습니다.