0

I have a Maven structure that builds just fine, but I somehow struggle with my Checkstyle resources. The structure is as follows:

  • Parent
    • Sub Parent A
      • Modules
    • Sub Parent B
      • Modules
    • Build Resources
      • src/main/resources files

The parent is supposed to define everything that both sub parents have in common. The Checkstyle plugin has the "Build Resources" as a dependency. The is defined as "/checktyle_resources/checkstyle.xml". I have problems with my Checkstyle plugin, because it can't find the neccessary resources, if I build the "Parent". If I build "Sub Parent A" or "Sub Parent B", checkstyle works fine, but of course the "Build Resources" have to be installed to the repository priorly.

Has somebody an idea why this won't work? Is this Maven structure even a good idea?

Thanks

PS: I have seen this question. And in the way the answer describes the solution it works in my project fine. But my multi-layered parent structure seems to create some kind of an issue here.

Here is the related content of the pom.xml of the parent.

<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>

Community
  • 1
  • 1
fancy
  • 2,077
  • 2
  • 23
  • 45
  • 1
    Please post your `pom.xml`. Do A and B (or their modules) properly declare a dependency on the resources project? – chrylis -cautiouslyoptimistic- Dec 03 '13 at 13:57
  • No, but the Checkstyle plugin in the parent does, which is inherited by the Sub Parents and their modules. If I build A Module or Sub Parent individually, everything works fine. I will add the pom.xml in a second. – fancy Dec 03 '13 at 14:02
  • A parent can't depend on one of its children; you should be getting Reactor errors about that. – chrylis -cautiouslyoptimistic- Dec 03 '13 at 14:05
  • I would if I had a direct dependency in the parent. But if the plugin has the dependency Maven seems okay with it (not saying this can't be the error). – fancy Dec 03 '13 at 14:16
  • 1
    You might better use in your top parent pom, to define the common configuration for Checkstyle plugin. That should avoid the kinda circular dependency. – Tome Dec 03 '13 at 14:18
  • I added the content of my parent pom.xml. There is already defined. – fancy Dec 03 '13 at 14:28
  • 1
    Does the subparents depend on group:build-tools? If so, where exactly is the build failing? There should not have any checkstyle-plugin execution unless it is specified in the section. – Tome Dec 03 '13 at 14:31
  • You are right, I accidentally cropped that part out (The pom is originally >1k lines (It was handed to me like that, now I try to clean it up)). No, the subparents do not depend on build-tools. – fancy Dec 03 '13 at 14:53
  • 1
    Then you should remove that plugin execution from the top-level parent, and only add it when needed (both sub-parents for instance). And to ensure the full build has proper reactor order, you should add a direct (optional) dependency towards build-tools in your sub-parents, so that you are sure that build-tools is built before the other modules needing it. – Tome Dec 03 '13 at 14:56

1 Answers1

0

Thanks for your help Tome and Chrylis.

The solution was indeed to remove the checkstyle-plugin from the -section of my parent-pom and put it in the sub-parent poms, while the configuration of the plugin is defined in the -section of the parent.

Now I still have checkstyle execution for the sub-parents when I build the Parent only and I don't have the redundancy of configuring it in every module individually.

fancy
  • 2,077
  • 2
  • 23
  • 45