Maven中主要和测试的不同Checkstyle规则提出问题

时间:2019-05-26 13:10:10

标签: maven maven-plugin checkstyle maven-surefire-plugin pmd

我必须对源文件夹和测试文件夹使用不同的checkstyle规则。对于pmd同样需要这样做。 已经尝试了链接Different Checkstyle Rules For Main And Test In Maven中的选项,但没有得到任何结果。给定的解决方案不考虑抑制规则。

这可能是解决方案Checkstyle different rules for different files,但希望使其更加通用。

如果无法引用2个不同的文件,那么我必须遵循上面的一个,但想尝试一次。

请引导我确定我在这里想念什么

两个文件夹的单个规则文件的工作代码

<checkstyle-maven-plugin.version>3.0.0</checkstyle-maven-plugin.version>


<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>${checkstyle-maven-plugin.version}</version>
            <configuration>
                <suppressionsLocation>/src/main/resources/config/checkstyle/suppression.xml</suppressionsLocation>
                <configLocation>/src/main/resources/config/checkstyle/checkstyle.xml</configLocation>
                <failOnViolation>false</failOnViolation>
                <excludes>**/Application.java,**/skjolberg/**/**,**/mapper/**,**/entity/**</excludes>
                <encoding>UTF-8</encoding>
                <consoleOutput>false</consoleOutput>
                <failsOnError>false</failsOnError>
            </configuration>
            <executions>
                <execution>
                    <id>validate</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build> 

我尝试了什么

	<reporting>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-checkstyle-plugin</artifactId>
				<version>2.6</version>
				<reportSets>
					<reportSet>
						<id>main_checks</id>
						<reports>
							<report>checkstyle</report>
						</reports>
						<configuration>
							<sourceDirectory>${project.build.sourceDirectory}</sourceDirectory>
							<includeTestSourceDirectory>false</includeTestSourceDirectory>
							<suppressionsLocation>/src/main/resources/config/checkstyle/suppression.xml</suppressionsLocation>
							<configLocation>/src/main/resources/config/checkstyle/checkstyle.xml</configLocation>
							<!-- <configLocation>checkstyle.xml</configLocation> -->
							<failOnViolation>false</failOnViolation>
							<excludes>**/PSCApplication.java,**/skjolberg/**/**,**/mapper/**,**/psc/entity/**</excludes>
							<encoding>UTF-8</encoding>
							<consoleOutput>false</consoleOutput>
							<failsOnError>false</failsOnError>
							<outputDirectory>${project.reporting.outputDirectory}/main-checks/</outputDirectory>
						</configuration>
					</reportSet>
					<reportSet>
						<id>test_checks</id>
						<reports>
							<report>checkstyle</report>
						</reports>
						<configuration>
							<sourceDirectory></sourceDirectory>
							<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
							<includeTestSourceDirectory>true</includeTestSourceDirectory>
							<suppressionsLocation>/src/main/resources/config/checkstyle/suppression.xml</suppressionsLocation>
							<configLocation>/src/main/resources/config/checkstyle/checkstyle-test.xml</configLocation>
							<!-- <configLocation>checkstyle.xml</configLocation> -->
							<failOnViolation>false</failOnViolation>
							<excludes>**/PSCApplication.java,**/skjolberg/**/**,**/mapper/**,**/psc/entity/**</excludes>
							<encoding>UTF-8</encoding>
							<consoleOutput>false</consoleOutput>
							<failsOnError>false</failsOnError>
							<outputDirectory>${project.reporting.outputDirectory}/test-checks/</outputDirectory>
						</configuration>
					</reportSet>
				</reportSets>
			</plugin>
		</plugins>
	</reporting>

我运行了mvn checkstyle:checkstyle命令,但是没有得到预期的结果。

0 个答案:

没有答案