我有一个构建得很好的 Maven 结构,但我不知何故在使用我的 Checkstyle 资源。结构如下:
- 家长
- 子父 A
- 模块
- 子父 B
- 模块
- 构建资源
- src/main/资源文件
- 子父 A
父母应该定义两个子父母共有的一切。Checkstyle 插件将“构建资源”作为依赖项。被定义为“/checktyle_resources/checkstyle.xml”。我的 Checkstyle 插件有问题,因为如果我构建“父级”,它找不到必要的资源。如果我构建“Sub Parent A”或“Sub Parent B”,checkstyle 工作正常,但当然“Build Resources”必须事先安装到存储库中。
有人知道为什么这不起作用吗?这个 Maven 结构是个好主意吗?
谢谢
PS:我看过这个问题。并且以答案的方式描述了它在我的项目中可以正常工作的解决方案。但是我的多层父结构似乎在这里产生了某种问题。
这里是父级的 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>