java - Sonar Lite 模式辅助类路径和 Ivy 依赖项

标签 java dependencies maven ivy sonarqube

我们的项目目前使用 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/

相关文章:

java - Fragment 中的 getActivity 在方向改变后为空(单 Pane 布局)

java - 查找未使用的 gradle 运行时依赖项

maven - 由于缺少执行数据错误而跳过 JaCoCo 执行

java - 如何创建相位器链/层

java - 无法启动 Log4j

java - Gradle 和 Spring-bootRun 找不到我的类(class)

java - 管理和报告大型项目的所有源项目的 Java Maven 依赖关系

java - Apache Karaf (4.2.6)外壳: Unable to install webconsole

java - 将多个 Maven 目标合并到一个事务中(例如部署和站点部署,如果站点部署失败怎么办?)

java - 在Android中编辑strings.xml文件内容