簡體   English   中英

Maven多模塊資源共享

[英]Maven Multi Module Resource Sharing

我有一個可以很好構建的Maven結構,但是我卻在某種程度上難以使用我的Checkstyle資源。 結構如下:

  • 父級
    • 子家長A
      • 模組
    • 子家長B
      • 模組
    • 建立資源
      • src / main / resources文件

父母應該定義兩個子父母共同擁有的一切。 Checkstyle插件具有“構建資源”作為依賴項。 的定義為“ /checktyle_resources/checkstyle.xml”。 我的Checkstyle插件存在問題,因為如果我構建了“父代”,則找不到所需的資源。 如果我構建“子父級A”或“子父級B”,則checkstyle可以正常工作,但是當然必須事先將“構建資源”安裝到資源庫中。

有人知道為什么這行不通嗎? 這個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>

感謝您的幫助Tome和Chrylis。

解決的方法的確是從父pom的-節中刪除checkstyle-plugin並將其放在子父poms中,而插件的配置在父pom的-節中定義。

現在,當我僅構建父級時,我仍然可以為子父級執行checkstyle執行,而我沒有多余的冗余在每個模塊中分別進行配置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM