mvn spotbugs:spotbugs 参数解释
通过maven构建执行spotbugs校验的小伙伴对下面这条命令一定不陌生:
mvn clean install -U spotbugs:spotbugs
通过上面的命令就可以在maven构建的时候完成spotbugs的检测功能了!
常用参数的解释
-
spotbugs:spotbugs 用于执行 SpotBugs 静态代码分析,并生成一个包含检测到的错误的报告。默认情况下,它不会使构建失败,但会生成一个报告供开发者查看。
-
spotbugs:check 执行静态代码分析,如果有错误将提示build失败,它非常适合集成到持续集成(CI)流程中,以确保代码质量。
通过mvn spotbugs:help查看更多的用法
执行命令 mvn spotbugs:help 就可以看到具体的使用方法
- spotbugs:check 这是最直接的目标,用于运行 SpotBugs 检查并在发现错误时失败构建。它非常适合集成到持续集成(CI)流程中,以确保代码质量。
- spotbugs:spotbugs 此目标用于执行 SpotBugs 分析,并生成一个包含检测到的错误的报告。默认情况下,它不会使构建失败,但会生成一个报告供开发者查看。
- spotbugs:gui 如果大家喜欢图形用户界面(GUI),可以使用此目标来启动 SpotBugs 的 GUI 版本,并直接在你的开发环境中查看和分析错误。这对于深入分析和理解错误特别有用。
-
spotbugs:verify 只是完成maven的基础构建工作,并没有执行spotbugs的检测功能(只是个人的测试结果,在网上暂时没有找到该参数的详细解释)
mvn spotbugs:help -Ddetail=true -Dgoal 参数
执行下面的命令,可以查看具体使用check 命令时,pom.xml文件中可以使用的参数
mvn spotbugs:help -Ddetail=true -Dgoal=check
spotbugs:check
Available parameters:
classFilesDirectory (Default: ${project.build.outputDirectory})
Required: Yes
debug (Default: false)
User property: spotbugs.debug
effort (Default: Default)
User property: spotbugs.effort
excludeBugsFile
User property: spotbugs.excludeBugsFile
excludeFilterFile
User property: spotbugs.excludeFilterFile
failOnError (Default: true)
User property: spotbugs.failOnError
failThreshold
User property: spotbugs.failThreshold
fork (Default: true)
User property: spotbugs.fork
includeFilterFile
User property: spotbugs.includeFilterFile
includeTests (Default: false)
User property: spotbugs.includeTests
jvmArgs
User property: spotbugs.jvmArgs
maxAllowedViolations (Default: 0)
User property: spotbugs.maxAllowedViolations
maxHeap (Default: 512)
User property: spotbugs.maxHeap
maxRank
User property: spotbugs.maxRank
nested (Default: false)
User property: spotbugs.nested
omitVisitors
User property: spotbugs.omitVisitors
onlyAnalyze
User property: spotbugs.onlyAnalyze
outputDirectory (Default: ${project.reporting.outputDirectory})
Required: Yes
outputEncoding (Default: ${project.reporting.outputEncoding})
User property: outputEncoding
pluginList
User property: spotbugs.pluginList
relaxed (Default: false)
User property: spotbugs.relaxed
skip (Default: false)
User property: spotbugs.skip
sourceEncoding (Default: ${project.build.sourceEncoding})
User property: encoding
spotbugsXmlOutputDirectory (Default: ${project.build.directory})
Required: Yes
spotbugsXmlOutputFilename (Default: spotbugsXml.xml)
User property: spotbugs.outputXmlFilename
testClassFilesDirectory (Default: ${project.build.testOutputDirectory})
Required: Yes
threshold (Default: Default)
User property: spotbugs.threshold
timeout (Default: 600000)
User property: spotbugs.timeout
trace (Default: false)
User property: spotbugs.trace
visitors
User property: spotbugs.visitors
xmlOutput (Default: false)
Required: Yes
User property: spotbugs.xmlOutput
xmlOutputDirectory (Default: ${project.build.directory})
Required: Yes
xrefLocation (Default: ${project.reporting.outputDirectory}/xref)
xrefTestLocation (Default: ${project.reporting.outputDirectory}/xref-test)
例如,在下面的pom.xml中的<configuration> 中可以设置上面所提及的参数
<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.my.demo</groupId>
<artifactId>PerformaceDemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.8.6.0</version>
<configuration>
<includeFilterFile>myfilter-include.xml</includeFilterFile>
<!-- <excludeFilterFile>myfilter-exclude.xml</excludeFilterFile>-->
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>
spotbugs:check命令后面可以使用的参数
mvn spotbugs:check -h
mvn spotbugs:check -h
usage: mvn [options] [<goal(s)>] [<phase(s)>]
Options:
-am,--also-make If project list is specified, also
build projects required by the
list
-amd,--also-make-dependents If project list is specified, also
build projects that depend on
projects on the list
-B,--batch-mode Run in non-interactive (batch)
mode (disables output color)
-b,--builder <arg> The id of the build strategy to
use
-C,--strict-checksums Fail the build if checksums don't
match
-c,--lax-checksums Warn if checksums don't match
--color <arg> Defines the color mode of the
output. Supported are 'auto',
'always', 'never'.
-cpu,--check-plugin-updates Ineffective, only kept for
backward compatibility
-D,--define <arg> Define a user property
-e,--errors Produce execution error messages
-emp,--encrypt-master-password <arg> Encrypt master security password
-ep,--encrypt-password <arg> Encrypt server password
-f,--file <arg> Force the use of an alternate POM
file (or directory with pom.xml)
-fae,--fail-at-end Only fail the build afterwards;
allow all non-impacted builds to
continue
-ff,--fail-fast Stop at first failure in
reactorized builds
-fn,--fail-never NEVER fail the build, regardless
of project result
-gs,--global-settings <arg> Alternate path for the global
settings file
-gt,--global-toolchains <arg> Alternate path for the global
toolchains file
-h,--help Display help information
-l,--log-file <arg> Log file where all build output
will go (disables output color)
-llr,--legacy-local-repository UNSUPPORTED: Use of this option
will make Maven invocation fail.
-N,--non-recursive Do not recurse into sub-projects
-npr,--no-plugin-registry Ineffective, only kept for
backward compatibility
-npu,--no-plugin-updates Ineffective, only kept for
backward compatibility
-nsu,--no-snapshot-updates Suppress SNAPSHOT updates
-ntp,--no-transfer-progress Do not display transfer progress
when downloading or uploading
-o,--offline Work offline
-P,--activate-profiles <arg> Comma-delimited list of profiles
to activate
-pl,--projects <arg> Comma-delimited list of specified
reactor projects to build instead
of all projects. A project can be
specified by [groupId]:artifactId
or by its relative path
-q,--quiet Quiet output - only show errors
-rf,--resume-from <arg> Resume reactor from specified
project
-s,--settings <arg> Alternate path for the user
settings file
-t,--toolchains <arg> Alternate path for the user
toolchains file
-T,--threads <arg> Thread count, for instance 4 (int)
or 2C/2.5C (int/float) where C is
core multiplied
-U,--update-snapshots Forces a check for missing
releases and updated snapshots on
remote repositories
-up,--update-plugins Ineffective, only kept for
backward compatibility
-v,--version Display version information
-V,--show-version Display version information
WITHOUT stopping build
-X,--debug Produce execution debug output
例如执行下面的命令,会把控制台中的输出内容写到文件log.txt中
mvn clean install spotbugs:check -l log.txt
我的每一篇文章都希望帮助读者解决实际工作中遇到的问题!如果文章帮到了您,劳烦点赞、收藏、转发!您的鼓励是我不断更新文章最大的动力!