我有一个Maven结构,它构建得很好,但不知何故,我很难使用Checkstyle资源。结构如下:
- 家长
- 子母公司A
- 模块
- 子母公司B
- 模块
- 构建资源
- src/main/resources文件
- 子母公司A
父项应该定义两个子父项的所有共同点。Checkstyle插件具有"构建资源"作为依赖项。定义为"/checkstyle_resources/checkstyle.xml"。我的Checkstyle插件有问题,因为如果我构建"Parent",它找不到必要的资源。如果我构建"Sub-Prental A"或"Sub-Pparent B",检查样式可以正常工作,但当然"构建资源"必须先安装到存储库中。
有人知道为什么这不起作用吗?这种Maven结构是个好主意吗?
感谢
附言:我看过这个问题。从答案描述解决方案的方式来看,它在我的项目中很好。但我的多层家长结构似乎在这里制造了某种问题。
以下是父级的pom.xml的相关内容。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group</groupId>
<artifactId>parent</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<target.jdk>1.6</target.jdk>
<build.module.versions>1.3</build.module.versions>
<compiler.source.level>${target.jdk}</compiler.source.level>
<compiler.target.level>${target.jdk}</compiler.target.level>
<compiler.version>${target.jdk}</compiler.version>
<maven.version>2.2.1</maven.version>
<maven.checkstyle.plugin.version>2.10</maven.checkstyle.plugin.version>
<checkstyle.fail.on.error>false</checkstyle.fail.on.error>
<junit.version>4.11</junit.version>
<checkstyle.version>5.4</checkstyle.version>
<checkstyle.skip>false</checkstyle.skip>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>group</groupId>
<artifactId>build-tools</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${maven.checkstyle.plugin.version}</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.version}</version>
<exclusions>
<exclusion>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>group</groupId>
<artifactId>build-tools</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>checkstyle</id>
<goals>
<goal>checkstyle</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<failsOnError>${checkstyle.fail.on.error}</failsOnError>
<failOnViolation>${checkstyle.fail.on.error}</failOnViolation>
<enableRulesSummary>false</enableRulesSummary>
<configLocation>/Checkstyle_Configuration/checks.xml</configLocation>
<headerLocation>/Checkstyle_Configuration/file_header_java_regexp.txt</headerLocation>
<suppressionsLocation>/Checkstyle_Configuration/suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file.donothing</suppressionsFileExpression>
<propertyExpansion>checkstyle.suppressions.file=${project.build.directory}/checkstyle-suppressions.xml</propertyExpansion>
<!-- <propertyExpansion>checkstyle.suppressions.file=Checkstyle_Configuration/suppressions.xml</propertyExpansion> -->
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<excludes>**/*Bean.java</excludes>
<excludes>**/gen*/*.java</excludes>
<skip>${checkstyle.skip}</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven.plugin.dependency.version}</version>
</plugin>
</plugins>
</pluginManagement>
<!--************************************************************************
* PLUGINS SECTION ************************************************************************* -->
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<inherited>false</inherited>
<configuration <configLocation>/Checkstyle_Configuration/volkswagen_checks.xml</configLocation> <headerLocation>/Checkstyle_Configuration/file_header_java_regexp.txt</headerLocation><suppressionsLocation>/Checkstyle_Configuration/suppressions.xml</suppressionsLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven.resources.version}</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
<!--****************************************************************************
* MODULES SECTION ***************************************************************************** -->
<modules>
<module>build-tools</module>
<module>sub-parent-a</module>
<module>sub-parent-b</module>
</modules>
感谢您的帮助Tome和Chrylis。
实际上,解决方案是从我的父pom的-部分中删除checkstyle插件,并将其放在子父pom中,而插件的配置则在父的-部分定义。
现在,当我只构建Parent时,我仍然可以执行子父级的检查样式,并且我没有在每个模块中单独配置它的冗余。