开发者

Sonar Lite Mode Aux Classpath & Ivy Dependencies

开发者 https://www.devze.com 2023-02-09 07:26 出处:网络
Our project currently uses Ivy for its dependency management. We would really like to integrate our Hudson build server with Sonar. So far this has been a relatively simple and straightforward task. O

Our project currently uses Ivy for its dependency management. We would really like to integrate our Hudson build server with Sonar. So far this has been a relatively simple and straightforward task. Of course we have set Sonar up to run in Sonar Lite mode (as we are not a Maven project).

Unfortunately, when our Sonar bytecode scan kicks in we get a lot of the following:

[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.

I understand that this is because our dependencies are not defined in our Sonar Lite dummy POM file and hence the libraries are not being picked to be traversed during the analysis.

The Sonar installation documentation mentions that the dependencies must be added to the aux classpath via the Maven pom file for this to be rectified. However, there does not seem to be any way to painlessly sync these dependencies with our ivy dependencies (of which there are hundreds). We obviously are lookin开发者_开发百科g for a way to define our dependencies without the need to replicate each one in our dummy pom file.

Several issues raised on the Sonar codehaus site (such as this one) seem to dance around the same feature that I'm looking for but none seem to offer a reasonable solution (unless I'm missing something).

Has anyone dealt with this situation before and has a reasonably good solution?

Thanks


Sonar lite mechanism now appears to be deprecated with Sonar 2.6.

Two new ways to integrate Sonar with a non Maven build:

  • ANT task
  • Java runner

The ANT task is tailor made for combination with ivy's control of the build and runtime classpaths (Using configurations):

<!--
  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>

Additionally note how the ivy info task can be used to set the Sonar key and version.


Have you tried an XSL transformation of the ivy.xml into your dummy pom.xml?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号