简体   繁体   中英

Maven Multi Module Resource Sharing

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM