当我使用 Sonar findbugs 进行代码审查时,它抛出异常,声称缺少某些类。
经过一番研究,很明显构建项目所需的 jar 应该包含在 pom.xml 中以供 Sonar 使用。
为此,Sonar 官方网站建议添加依赖项:
<dependencies>
<dependency>
<groupId>com.opensymphony</groupId>
<artifactId>xwork-core</artifactId>
<version>2.1.6</version>
<scope>system</scope>
<systemPath>${basedir}/.../xwork-core.jar</systemPath>
</dependency>
</dependencies>
但是,对我来说,它仍然不起作用。
我使用的是Windows,请问有人可以告诉我如何配置吗,特别是系统路径?
这是项目一个模块的 pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>DB</groupId>
<artifactId>Project1</artifactId>
<name>project1</name>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.opensymphony</groupId>
<artifactId>xwork-core</artifactId>
<version>2.1.6</version><!--installed into .m2 folder, local repository, then refer it-->
</dependency>
<dependency>
<groupId>dep</groupId>
<artifactId>dep1</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib//asn.jar</systemPath>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<outputDirectory>build-to/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
<excludes>
<exclude>**/*.*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
</project>
您的项目是否已经是一个 Maven 项目,或者您是否正在使用 ant 或其他工具编译内容,然后尝试让声纳对其运行?对于非常复杂的项目,声纳光模式可能会很棘手。如果您有一个多模块项目,我会在声纳的本地副本下工作最简单的项目,然后努力添加更多模块。
此外,我会尝试将文件本地复制到不从 ${basedir} 升级的其他目录。看看是否有帮助。所以 ${basedir}/lib/xwork-core.jar 类似的东西。
也许对于声纳分析,您可以有一个单独的任务将所需的库复制到可以适当访问的临时文件夹,然后在分析完成后将其删除。
我发现了问题。声纳的官方文档实际上是错误的。 “mvn sonar:sonar”将调用maven sonar插件2.0 beta,这不会启用库jar的依赖工作。相反,调用“mvn sonar3:sonar”,调用最新版本的 Maven 声纳插件 2.4.1。