Spring Cloud Kubernetes Checkstyle配置

2024-01-08 17:38 更新

Checkstyle規(guī)則默認禁用。要將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違規(guī)而無法構建
  3. Checkstyle還分析測試源
  4. 添加Spring Java格式插件,該插件將重新格式化您的代碼以通過大多數Checkstyle格式設置規(guī)則
  5. 將Checkstyle插件添加到您的構建和報告階段

如果您需要取消某些規(guī)則(例如,行長需要更長),那么只需在${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復制到您的項目中。這樣,將應用一些默認格式設置規(guī)則。 您可以通過運行以下腳本來這樣做:

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


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號