Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven, filtering NON-resource file

Tags:

maven-2

I share a config file between several modules and I don't want the config file to be baked into any of the JARs.

How can i make Maven do (resource) filtering on the file which is not specified as a resource but is in a config folder on the same level as the root POM?

like image 429
bob Avatar asked Aug 02 '10 14:08

bob


1 Answers

You could use the Maven Resources Plugin and its resources:copy-resources mojo. From the Examples:

Copy Resources

You can use the mojo copy-resources to copy resources which are not in the default maven layout or not declared in the build/resources element and attach it to a phase

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.4.3</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>validate</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/extra-resources</outputDirectory>
              <resources>          
                <resource>
                  <directory>src/non-packaged-resources</directory>
                  <filtering>true</filtering>
                </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

Another option would be to use the Maven AntRun Plugin and Ant filtering capabilities (e.g. with the Filter and/or the Copy tasks) but the above looks just fine.

like image 71
Pascal Thivent Avatar answered Oct 12 '22 03:10

Pascal Thivent