【问题标题】:Share filter file amoung modules在模块之间共享过滤器文件
【发布时间】:2011-06-02 08:17:15
【问题描述】:

我和这张海报有同样的问题

How to share a filter file among Maven2 modules?

在所有子项目和子项目的子项目之间共享过滤文件

我实施了 Rich Seller 提供的解决方案……这个特别的解决方案有效。 "或者,您可以将过滤器文件指定为某些构建的附加工件"

但在构建结束时,我收到一条错误消息

安装 /..../spring/hibernate/search/src/main/resources/shared-filter.properties 到 /.../spring-hibernate-search-1.0-SNAPSHOT-filter.properties

[错误]构建错误 安装工件时出错:文件 /..../spring/hibernate/search/src/main/resources/shared-filter.properties 不存在

我猜 Maven 正在尝试安装父 pom 中提供的工件

 <configuration>
                        <artifacts>
                            <artifact>
                                <file>src/main/resources/shared-filter.properties</file>
                                <type>properties</type>
                                <classifier>filter</classifier>
                            </artifact>
                        </artifacts>
                    </configuration>

有没有办法告诉 Maven 在构建孩子时不要安装这个工件

请帮忙,坚持一段时间

***********新增功能***************

我的父 pom 有以下内容

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <id>attach-artifacts</id>
                    <phase>package</phase>
                    <goals>
                        <goal>attach-artifact</goal>
                    </goals>
                    <configuration>
                        <artifacts>
                            <artifact>
                                <file>src/main/resources/filters/mradha.filter.properties</file>
                                <type>properties</type>
                                <classifier>filter</classifier>
                            </artifact>
                        </artifacts>
                    </configuration>
                </execution>
            </executions>
        </plugin>

<pluginManagement>
        <plugins>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.merc</groupId>
                                    <artifactId>MavenMasterProject</artifactId>
                                    <version>1.0-SNAPSHOT</version>
                                    <classifier>filter</classifier>
                                    <type>properties</type>
                                    <overWrite>false</overWrite>
                                    <destFileName>mradha.filter.properties</destFileName>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>
                            ${project.build.directory}/filters
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </pluginManagement>

我的子项目或模块有以下内容

<build>
    <filters>
        <filter>${project.build.directory}/filters/mradha.filter.properties</filter>
    </filters>

    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

    <plugins>
        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
        </plugin>
    </plugins>
</build>     

当我点击子项目或模块并进行安装时,它会尝试安装附加的工件并且我得到构建失败

【问题讨论】:

    标签: maven


    【解决方案1】:

    上面发布的xml sn-p 是否存在于每个孩子身上?如果是这样,这就解释了问题。

    如果您仔细执行@Rich Seller 在链接的 SO 帖子中建议的步骤,则父项目应使用build-helper-maven-plugin 过滤器工件attach。需要过滤的子级应使用maven-dependency-plugin 以使此过滤器在generate-sources 阶段可用。然后他们应该使用带有&lt;filter&gt; 和&lt;resource&gt; 标签的过滤器。

    【讨论】:

    • 我已将我的父项目和子项目 pom 的内容添加到上述帖子中。请看一下。据我所知,我所做的与 Rich Seller 提到的完全相同
    • 嗯!在一个地方是shared-filter.properties,在另一个地方是mradha.filter.properties。会不会是这个问题?
    • 这是一个复制粘贴错误。我复制了 Rich Seller 上一篇文章中的实际代码。然后我添加了我自己的代码。您实际上是在使用这个实现还是基于您猜测它应该可以工作的代码。
    【解决方案2】:

    我刚刚解决了完全相同的问题。我们有更多的项目嵌套结构,我首先定义了“filters.path”属性

       <properties>
           <filters.path>../../filters</filters.path>
       </properties>
    

    项目结构(过滤规则)符合以下模式:

            <filters>
                     <filter>${filters.path}/filter-${env}.properties</filter>
                     <filter>${filters.path}/filter-shared.properties</filter>
            </filters>
    

    我只有 2 个需要自定义过滤的项目,我只是更改了 'filters.path' 属性

    <properties>
        <env>dev</env>
        <filters.path>../filters</filters.path>
    
        <jbehave-revision>3.4.5</jbehave-revision>
        <xmlunit-revision>1.3</xmlunit-revision>
        <scale4j-revision>0.2</scale4j-revision>
    </properties>
    

    希望这能有所帮助!

    【讨论】:

    • 在子模块中配置过滤器并在父模块中声明属性的简单易行! - 有效!谢谢@Andrew
    猜你喜欢
    • 2010-12-04
    • 2016-04-20
    • 2017-01-21
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多