0

I have the same question as this poster

How to share a filter file among Maven2 modules?

share filter file among all sub projects and sub projects of sub projects

I implemented the solution provided by Rich Seller...this particular one and it works. "Alternatively, you can specify a filter file as an attached artifact on some build"

But at the end of the build, i get an error message

Installing /..../spring/hibernate/search/src/main/resources/shared-filter.properties to /.../spring-hibernate-search-1.0-SNAPSHOT-filter.properties

[ERROR]BUILD ERROR Error installing artifact: File /..../spring/hibernate/search/src/main/resources/shared-filter.properties does not exist

I am guessing Maven is trying to install the artifact proivded in the parent pom

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

Is there a way to tell Maven not to install this artifact while building the childrens

PLEASE HELP, STUCK ON THIS FOR A WHILE

***********new addition***************

my parent pom has the following

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

My sub project or modules have the following

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

When i click on the sub project or module and do install, it tries to install the attached artifact and I get the build failure

Community
  • 1
  • 1
user373201
  • 10,945
  • 34
  • 112
  • 168

2 Answers2

2

I just fixed exactly the same problem. We have even more nested structure of projects and I defined 'filters.path' property first

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

The structure of projects (filtering rules) matched following pattern:

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

I have only 2 projects where custom filtering was required and i just changed the 'filters.path' property

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

Hope this can help!

Andrew
  • 21
  • 2
  • simple and easy one to configure the filters in child module declaring the properties in parent module! - It worked! Thanks @Andrew – Alhuck May 20 '18 at 08:42
0

Is the xml snippet posted above present in each children? If so, that explains the problem.

If you carefully go through the steps suggested by @Rich Seller in the linked SO post, the parent project should attach the filter artifact using build-helper-maven-plugin. The children which require filtering should use maven-dependency-plugin to have this filter available during the generate-sources phase. They should then use the filter using the <filter> and <resource> tags.

Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • I have added the contents of my parent and sub project poms to the above post. Please take a look. As far as i know i am doing exactly the same as mentioned by Rich Seller – user373201 Jan 02 '11 at 04:18
  • Hmm! in one place it is shared-filter.properties and in another mradha.filter.properties. Could that be the issue? – Raghuram Jan 03 '11 at 02:12
  • that is a copy paste error. I copied the actual code in the previous post by Rich Seller. Then I added my own code. Are you actually using this implementation or based on the code you are guessing that it should work. – user373201 Jan 06 '11 at 18:20