2016-04-13 52 views
3

我有幾個嵌套的Maven項目級別,其中每個模塊都可以參與全局集成測試。爲了有一個全球性的,多模塊的覆蓋,我已經使用Maven的變量${session.executionRootDirectory}配置jacoco使用和分享翻過模塊相同的文件,:

<execution> 
    <id>pre-integration-test</id> 
    <phase>pre-integration-test</phase> 
    <goals> 
     <goal>prepare-agent-integration</goal> 
    </goals> 
    <configuration> 
     <propertyName>jacoco.failsafeArgLine</propertyName> 
     <destFile>${session.executionRootDirectory}/target/jacoco-it.exec</destFile> 
    </configuration> 
</execution> 

這樣,相同的數據文件由每個模塊,無論它嵌套在子模塊中有多深。我檢查過,啓動「mvn clean install」時,jacoco生成了一個正確的數據文件。

現在問題出現時啓動mvn sonar:sonar。看來插件不能用真正的路徑替換那個變量。使用@{session.executionRootDirectory}時,我可以看到下面的日誌

[INFO] JaCoCoItSensor: JaCoCo IT report not found: /home/tomcat/.jenkins/jobs/MYJOB/workspace/${session.executionRootDirectory}/target/jacoco-it.exec 

它不工作得更好。

任何解決方法?

回答

0

a comment in this bug report at SonarSource,建議採用以下配置:

<plugin> 
    <groupId>com.github.goldin</groupId> 
    <artifactId>properties-maven-plugin</artifactId> 
    <version>0.2.5</version> 
    <executions> 
     <execution> 
      <id>set-sonar.jacoco.reportPath</id> 
      <goals> 
       <goal>set-properties</goal> 
      </goals> 
      <phase>initialize</phase> 
      <configuration> 
       <rawProperties> 
        sonar.jacoco.itReportPath = ${session.executionRootDirectory}/target/jacoco-it.exec 
       </rawProperties> 
       <addDollar>true</addDollar> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

...這是不幸的是沒有與Maven 3.1+兼容的,我已經使用和來源that fork建,然後我就能夠使一切正常工作與Maven 3.2.3。