我们的项目目前使用 Ivy 进行依赖管理。我们真的很想将我们的 Hudson 构建服务器与 Sonar 集成。到目前为止,这是一项相对简单直接的任务。当然,我们已经将 Sonar 设置为在 Sonar Lite 模式下运行(因为我们不是 Maven 项目)。
不幸的是,当我们的 Sonar 字节码扫描启动时,我们会得到以下很多信息:
[WARN] Class 'XXX' is not accessible through the ClassLoader. [WARN] Class 'XXX' is not accessible through the ClassLoader. ... [WARN] Class 'XXX' is not accessible through the ClassLoader.
我知道这是因为我们的依赖项没有在我们的 Sonar Lite 虚拟 POM 文件中定义,因此在分析过程中没有选择要遍历的库。
Sonar installation documentation提到必须通过 Maven pom 文件将依赖项添加到辅助类路径才能纠正此问题。然而,似乎没有任何方法可以轻松地将这些依赖项与我们的 ivy 依赖项(其中有数百个)同步。我们显然正在寻找一种方法来定义我们的依赖项,而无需在我们的虚拟 pom 文件中复制每个依赖项。
Several issues在 Sonar codehaus 网站上提出的(例如 this one)似乎围绕着我正在寻找的相同功能跳舞,但似乎没有一个提供合理的解决方案(除非我遗漏了什么)。
有没有人处理过这种情况并且有一个相当好的解决方案?
谢谢
最佳答案
Sonar lite 机制现在似乎已被 Sonar 2.6 弃用。
将 Sonar 与非 Maven 构建集成的两种新方法:
ANT 任务是为结合 ivy 对构建和运行时类路径(使用配置)的控制而量身定制的:
<!--
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>
另外请注意 ivy info 任务如何用于设置 Sonar key 和版本。
关于java - Sonar Lite 模式辅助类路径和 Ivy 依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4928638/