简体   繁体   English

Maven多模块资源共享

[英]Maven Multi Module Resource Sharing

I have a Maven structure that builds just fine, but I somehow struggle with my Checkstyle resources. 我有一个可以很好构建的Maven结构,但是我却在某种程度上难以使用我的Checkstyle资源。 The structure is as follows: 结构如下:

  • Parent 父级
    • Sub Parent A 子家长A
      • Modules 模组
    • Sub Parent B 子家长B
      • Modules 模组
    • Build Resources 建立资源
      • src/main/resources files src / main / resources文件

The parent is supposed to define everything that both sub parents have in common. 父母应该定义两个子父母共同拥有的一切。 The Checkstyle plugin has the "Build Resources" as a dependency. Checkstyle插件具有“构建资源”作为依赖项。 The is defined as "/checktyle_resources/checkstyle.xml". 的定义为“ /checktyle_resources/checkstyle.xml”。 I have problems with my Checkstyle plugin, because it can't find the neccessary resources, if I build the "Parent". 我的Checkstyle插件存在问题,因为如果我构建了“父代”,则找不到所需的资源。 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. 如果我构建“子父级A”或“子父级B”,则checkstyle可以正常工作,但是当然必须事先将“构建资源”安装到资源库中。

Has somebody an idea why this won't work? 有人知道为什么这行不通吗? Is this Maven structure even a good idea? 这个Maven结构甚至是个好主意吗?

Thanks 谢谢

PS: I have seen this question. PS:我已经看到了这个问题。 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. 这是父级的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>

Thanks for your help Tome and Chrylis. 感谢您的帮助Tome和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. 解决的方法的确是从父pom的-节中删除checkstyle-plugin并将其放在子父poms中,而插件的配置在父pom的-节中定义。

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. 现在,当我仅构建父级时,我仍然可以为子父级执行checkstyle执行,而我没有多余的冗余在每个模块中分别进行配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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