3

I'm developing a Maven parent project (not aggregator!) project which contains Maven plugins and other things which I repeat in almost every project and which I want to use in projects through the

<parent>
    <groupId>richtercloud</groupId>
    <artifactId>maven-parent</artifactId>
    <version>1</version>
    <relativePath></relativePath>
</parent>

idiom. relativePath is empty because resolution ought to occur throught the Maven cache as you probably know if you feel ready to answer this question.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>2.17</version>
    <executions>
        <execution>
            <id>check_style</id>
            <goals>
                <goal>check</goal>
            </goals>
            <phase>validate</phase>
            <configuration>
                <includeTestSourceDirectory>true</includeTestSourceDirectory>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <configLocation>check_style.xml</configLocation>
    </configuration>
</plugin>

and thus maven-checkstyle-plugin is used in all projects containing parent directive above.

The thing is that

  • either the plugin section above is put into reporting in the parent (without the executions because that'd be invalid), then the configuration is ignored and consequently the default XML being used
  • or the plugin section is put into build in the parent POM, then the parent project doesn't compile because it doesn't search the file specified in configLocation in classpath (which it should afaik) and thus fails due to Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (check_style) on project maven-parent: Failed during checkstyle execution: Unable to find configuration file at location: check_style.xml: Could not find resource 'check_style.xml'. -> [Help 1]. Prepending src/main/resources helps to compile the parent, but causes failure in all other project because they resolve configLocation to src/main/resources/src/main/resources/check_style.xml which is correct. A bug?

This is not answered by Maven inherit parent module resources because the question doesn't specify how it references the parent project, i.e. with which relativePath.

I'm using Maven 3.3.9.

Community
  • 1
  • 1
Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
  • It does look the `configLocation` in the classpath. It fails building the parent because, when the parent is build, it doesn't have it (since the parent is declaring the plugin with `` not in `` there is no reason it should be exempt from the checktyle). A better solution (IMO) would be refactor your `check_style.xml` in the parent's classpath, or refactor it into a shared library that the plugin's declaration in the parent depends on. – Tunaki Feb 08 '17 at 20:32

0 Answers0