Spring Cloud Kubernetes Checkstyle配置

2024-01-08 17:38 更新

Checkstyle规则默认禁用要将checkstyle添加到项目中,只需定义以下属性和插件。

pom.xml。 

<properties>
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError> 
        <maven-checkstyle-plugin.failsOnViolation>true
        </maven-checkstyle-plugin.failsOnViolation> 
        <maven-checkstyle-plugin.includeTestSourceDirectory>true
        </maven-checkstyle-plugin.includeTestSourceDirectory> 
</properties>

<build>
        <plugins>
            <plugin> 
                <groupId>io.spring.javaformat</groupId>
                <artifactId>spring-javaformat-maven-plugin</artifactId>
            </plugin>
            <plugin> 
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
        </plugins>

    <reporting>
        <plugins>
            <plugin> 
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-checkstyle-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>
</build>

  1. 因Checkstyle错误而无法构建
  2. 因Checkstyle违规而无法构建
  3. Checkstyle还分析测试源
  4. 添加Spring Java格式插件,该插件将重新格式化您的代码以通过大多数Checkstyle格式设置规则
  5. 将Checkstyle插件添加到您的构建和报告阶段

如果您需要取消某些规则(例如,行长需要更长),那么只需在${project.root}/src/checkstyle/checkstyle-suppressions.xml下定义一个文件就可以了。例:

projectRoot / src / checkstyle / checkstyle-suppresions.xml。 

<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
		"-//Puppy Crawl//DTD Suppressions 1.1//EN"
		"https://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
	<suppress files=".*ConfigServerApplication\.java" checks="HideUtilityClassConstructor"/>
	<suppress files=".*ConfigClientWatch\.java" checks="LineLengthCheck"/>
</suppressions>

建议将${spring-cloud-build.rootFolder}/.editorconfig${spring-cloud-build.rootFolder}/.springformat复制到您的项目中。这样,将应用一些默认格式设置规则。 您可以通过运行以下脚本来这样做:

$ curl https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/master/.editorconfig -o .editorconfig
$ touch .springformat


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号