2011-02-08 69 views
1

我們的項目目前使用Ivy進行依賴管理。我們真的很想將我們的Hudson構建服務器與Sonar集成在一起。到目前爲止,這是一個相對簡單而直接的任務。當然,我們已經將Sonar設置爲以Sonar Lite模式運行(因爲我們不是Maven項目)。聲納精簡版模式輔助類路徑和常春藤依賴項

不幸的是,當我們在我們的聲納掃描字節碼踢得到了不少如下:

[WARN]類「XXX」是無法通過的ClassLoader訪問 。 [WARN]類 'XXX'不能通過 ClassLoader訪問。 ... [WARN]類'XXX' 不能通過 ClassLoader訪問。

我知道這是因爲我們的依賴關係沒有在我們的Sonar Lite虛擬POM文件中定義,因此在分析過程中沒有選擇要遍歷的庫。

Sonar installation documentation提到必須通過Maven pom文件將相關性添加到aux類路徑中才能糾正此問題。但是,似乎沒有任何方法可以輕鬆地將這些依賴項與我們的常春藤依賴項(其中有數百項)相互同步。我們顯然正在尋找一種方法來定義我們的依賴關係,而不需要在我們的虛擬pom文件中複製每個依賴關係。

Several issues在Sonar codehaus網站(例如this one)上提出似乎圍繞我尋找的相同功能舞蹈,但似乎沒有提供合理的解決方案(除非我失去了一些東西)。

有沒有人處理過這種情況,並有一個相當好的解決方案?

感謝

回答

2

Sonar lite機制現在似乎與聲納2.6不贊成使用。

兩種新方式,聲納與非Maven構建整合:

Ant任務是特製的組合構建和運行時類路徑的常春藤的控制方面(使用配置):

<!-- 
    Uses ivy to download dependencies 
    --> 

    <target name="dependencies" description="Resolve project dependencies and set classpaths"> 
    <ivy:resolve/> 
    <ivy:cachepath pathid="compile.path" conf="compile"/> 
    <ivy:cachepath pathid="runtime.path" conf="runtime"/> 
    <ivy:cachepath pathid="test.path"  conf="test"/> 
    <ivy:cachepath pathid="anttasks.path" conf="anttasks"/> 
    </target> 

    <!-- 
    Perform source code analysis 
    --> 

    <target name="sonar-init" description="Declare sonar ant task"> 
    <taskdef uri="antlib:org.sonar.ant" 
      resource="org/sonar/ant/antlib.xml" 
      classpathref="anttasks.path"/> 
    </target> 

    <target name="sonar" depends="test,sonar-init" description="Run the Sonar code analysis tool"> 
    <ivy:info/> 

    <sonar:sonar workDir="${sonar.workDir}" key="${ivy.organisation}:${ivy.module}" version="${ivy.revision}"> 
     <!-- Project layout --> 
     <sources> 
     <path location="${build.srcDir}"/> 
     </sources> 
     <tests> 
     <path location="${build.testDir}"/> 
     </tests> 
     <binaries> 
     <path location="${build.outputDir}"/> 
     <path location="${build.testOutputDir}"/> 
     </binaries> 
     <libraries> 
     <path refid="test.path"/> 
     </libraries> 
     <!-- Additional Sonar configuration --> 
     <property key="sonar.java.source" value="1.5"/> 
     <property key="sonar.java.target" value="1.5"/> 
    </sonar:sonar> 
    </target> 

此外請注意常規任務可用於設置Sonar密鑰和版本。

1

您是否嘗試過的ivy.xml的XSL轉換到您的虛擬pom.xml的?

+0

克里斯,不,我沒有考慮使用XSLT,但我喜歡這個想法。我會仔細看看的。 – S73417H 2011-02-08 14:43:14

+0

有一點Google搜索會顯示makepom ant任務(http://ant.apache.org/ivy/history/2.2.0/use/makepom.html)。這可能是將我尋求的內容集成到現有構建腳本中的一種很好的方式。 我會進一步研究它... – S73417H 2011-02-08 14:49:16