0
点赞
收藏
分享

微信扫一扫

checkstyle教程:Maven多模块工程的 maven-checkstyle-plugin 配置示例


<project>
  ...
    <build>
        <pluginManagement>
            <plugins>
               <!-- compiler在maven声明周期内置,所以后面不用声明也可使用 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                        <encoding>${project.build.sourceEncoding}</encoding>
                    </configuration>
                </plugin>
		<!-- 公共checkstyle标准配置,可以在子模块中覆盖,修改自定义选项 -->
		<plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-checkstyle-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <configLocation>/script/goose_checkstyle.xml</configLocation>
                        <includeTestSourceDirectory>false</includeTestSourceDirectory>
                        <consoleOutput>true</consoleOutput>
                        <encoding>${project.build.sourceEncoding}</encoding>
                        <skip>false</skip>
                        <!--这里是说当前这个配置是什么错误级别。如果配置的是error,那么扫描到不符合条件的,就是打印error。checkstyle里允许的错误级别有error, warning, info. -->
                        <violationSeverity>error</violationSeverity>
                        <!-- 是否打断命令执行,错误的时候会停止。否则,错误会生成报告,但不会阻止命令执行。 -->
                        <failsOnError>false</failsOnError>
                    </configuration>
                    <executions>
                        <execution>
                            <id>validate</id>
                            <phase>validate</phase>
                            <goals>
                                <goal>checkstyle</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <!--所有子模块都要执行的plugin-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-site-plugin</artifactId>
                <version>3.7.1</version>
            </plugin>
        </plugins>
    </build>
    <reporting>
	<!-- 所有子模块都要执行的报告 -->
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <version>3.1.0</version>
                <reportSets>
                    <reportSet>
                        <reports>
                            <report>checkstyle</report>
                        </reports>
                    </reportSet>
                </reportSets>
            </plugin>
        </plugins>
    </reporting>
  ...
</project>

links:
https://ld246.com/article/1613814037505


举报

相关推荐

0 条评论