detekt maven plugin
1.23.7
包装Detekt CLI的Maven插件。它支持与Detekt CLI相同的参数。
请参阅下面的配置后如何执行。
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >使用上面的配置DETEKT将扫描源文件中的${basedir}/src ,并将结果输出${basedir}/detekt 。
可以在插件中配置Detekt版本1.23.7的所有参数。
该插件支持本地文件作为要传递给Detekt的配置。
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
< configuration >
< config >config/detekt/detekt.yml</ config >
</ configuration >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >可以列出多个文件;作为分离器。
该插件支持HTTP和HTTPS上的远程配置。
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
< configuration >
< config >https://raw.githubusercontent.com/Ozsie/detekt-maven-plugin/fd0de6d59e6ae1e062a9d2b030a171da1d3225ab/src/test/resources/resolve-config/remote/remote-config.yml</ config >
</ configuration >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >DETEKT支持在Detekt插件中包装的规则集,处理器,报告等。
有关已知插件列表,请参见Detekt Marketplace。
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
</ execution >
</ executions >
< dependencies >
<!-- Detekt's first-party unbundled plugin for library authors:
https://detekt.dev/docs/next/rules/libraries -->
< dependency >
< groupId >io.gitlab.arturbosch.detekt</ groupId >
< artifactId >detekt-rules-libraries</ artifactId >
< version >1.23.7</ version >
</ dependency >
</ dependencies >
</ plugin >
</ plugins >
</ build >< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
< configuration >
< plugins >
< plugin >local/path/to/plugin.jar</ plugin >
</ plugins >
</ configuration >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >有关支持的报告类型,请参见Detekt文档。
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
< configuration >
< report >
< report >txt:reports/detekt.txt</ report >
< report >xml:reports/detekt.xml</ report >
</ report >
</ configuration >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >或者,可以将配置放置在<executions>之外。这允许在独立运行目标时使用配置。
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< configuration >
< report >
< report >txt:reports/detekt.txt</ report >
< report >xml:reports/detekt.xml</ report >
</ report >
</ configuration >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >首先需要生成基线文件:
mvn detekt:cb这将为每个模块生成一个名为baseline-<module-name>.xml 。有关生成基准的更多信息,请参见Create-Baseline。现在,您可以在配置中引用基线文件,如下所示。
< build >
< plugins >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< configuration >
< baseline >baseline.xml</ baseline >
</ configuration >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >check</ goal ></ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >有关说明,请参见第144期。
< build >
< plugins >
< plugin >
< groupId >org.apache.maven.plugins</ groupId >
< artifactId >maven-dependency-plugin</ artifactId >
< version >3.2.0</ version >
< executions >
< execution >
< id >generate-classpath-var</ id >
< phase >package</ phase >
< goals >< goal >build-classpath</ goal ></ goals >
< configuration >
< outputProperty >generated.classpath</ outputProperty >
< silent >true</ silent >
</ configuration >
</ execution >
</ executions >
</ plugin >
< plugin >
< groupId >com.github.ozsie</ groupId >
< artifactId >detekt-maven-plugin</ artifactId >
< version >1.23.7</ version >
< configuration >
< baseline >baseline.xml</ baseline >
< classPath >${generated.classpath}</ classPath >
< jvmTarget >17</ jvmTarget >
</ configuration >
< executions >
< execution >
< phase >verify</ phase >
< goals >< goal >ctr</ goal ></ goals >
</ execution >
</ executions >
</ plugin >
</ plugins >
</ build >check用于运行detekt。所有CLI参数(不包括-GC和-CB)都可以使用-ddetekt。
例子
mvn detekt:check -Ddetekt.config=detekt.ymlmvn detekt:check -Ddetekt.debug=true如果您需要类型分辨率,请改用以下内容
mvn detekt:ctr -Ddetekt.config=detekt.ymlmvn detekt:ctr -Ddetekt.debug=truecreate-baseline用于创建基线。所有CLI参数(不包括-GC和-CB)都可以使用-ddetekt。{parameter}获得。默认情况下,将生成一个称为基线-.xml的文件。如果在呼叫中包含-ddetekt.baseline,则可以为基线文件指定其他名称。
例子
mvn detekt:cb -Ddetekt.config=detekt.ymlmvn detekt:cb -Ddetekt.debug=truemvn detekt:cb -Ddetekt.baseline=some-other-baseline.xmlmvn detekt:create-baseline -Ddetekt.config=detekt.ymlmvn detekt:create-baseline -Ddetekt.debug=truegenerate-config用于生成默认配置文件。
例子
mvn detekt:gcmvn detekt:generate-config