SpotBugs-Maven-Plugin配置

习旻
2023-12-01

1.pom.xml设定:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.mkyong.examples</groupId>
    <artifactId>maven-static-code-analysis</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <!-- https://maven.apache.org/general.html#encoding-warning -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <spotbugs.version>4.2.0</spotbugs.version>
        <pmd.version>3.11.0</pmd.version>
    </properties>

    <reporting>
        <plugins>
            <!-- https://spotbugs.github.io/ -->
            <!-- https://spotbugs.github.io/spotbugs-maven-plugin/usage.html -->
            <plugin>
                <groupId>com.github.spotbugs</groupId>
                <artifactId>spotbugs-maven-plugin</artifactId>
                <version>${spotbugs.version}</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-pmd-plugin</artifactId>
                <version>${pmd.version}</version>
            </plugin>

        </plugins>
    </reporting>

    <build>
        <finalName>maven-static-code-analysis</finalName>
        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-project-info-reports-plugin</artifactId>
                <version>3.0.0</version>
            </plugin>

            
        </plugins>
    </build>

</project>

2.本地Maven安装:

从官方下载,下载页面:http://maven.apache.org/download.cgi

配置MAVEN_HOME =F:\Ide\apache-maven-3.6.3

以及 在path环境变量中添加:%MAVEN_HOME%\bin

测试:按住win+R 输入cmd,进入黑窗口控制台。输入命令: mvn -version

3.Maven设定:

%MAVEN_HOME%\conf\settings.xml

3-1.本地仓库

  <localRepository>
       C:\Users\用户名\.m2\repository
  </localRepository>

3-2.阿里云仓库

	 <mirrors>

    <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>        
    </mirror>


		<mirror>
		  <id>central</id>
		  <name>Maven Repository Switchboard</name>
		  <url>http://repo1.maven.org/maven2/</url>
		  <mirrorOf>central</mirrorOf>
		</mirror>
    </mirrors>

3-3.jdk的设定

一定要在<profiles></profiles>内部

    <profile>
      <id>jdk-1.8</id>

      <activation>
        <jdk>1.8</jdk>
        <activeByDefault>true</activeByDefault>
      </activation>

      <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
		<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
      </properties>
    </profile>

4.SpotBugs运行:

   cd maven工程目录

   mvn compile site 执行

5.SpotBugs报告:

maven工程\target\site\spotbugs.html

 类似资料: