Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying multiple resource directories to independent target directories with maven

Tags:

java

maven

The Maven resources plugin:

This goal requires that you configure the resources to be copied, and specify the outputDirectory.

Copy two (or more) external resource directories within the basedir to the build output directory using maven (see blah and uggh).

${basedir}/    - pom.xml   - blah/   - uggh/   - src/     - main/..     - test/..   - target/     - classes/..     - blah/     - uggh/ 

For example, given the directory structure above copy blah and uggh to the target directory using maven. It is easy to copy one or the other, however, the plugin only accepts a single outputDirectory. If you specify the target directory and both directories as resources, then the contents of each directory gets copied to target but not the directories themselves.

Additional use of the plugin overwrites the initial. Also, I've tried specifying the entire basedir and only including the desired directories. This does not copy anything.

Here is an example of copying a single directory:

  <plugin>     <artifactId>maven-resources-plugin</artifactId>     <version>2.6</version>     <executions>       <execution>         <id>copy-resources</id>         <phase>validate</phase>         <goals>           <goal>copy-resources</goal>         </goals>         <configuration>           <outputDirectory>${basedir}/target/blah</outputDirectory>           <resources>             <resource>                 <directory>blah</directory>                 <filtering>true</filtering>             </resource>           </resources>         </configuration>       </execution>     </executions>   </plugin> 
like image 294
bnjmn Avatar asked Oct 16 '13 16:10

bnjmn


1 Answers

This is where the file ends up:

<outputDirectory>${basedir}/target/blah</outputDirectory> 

This is where it is copied from:

<directory>src/main/otherresources</directory> 

There would be an <include> or <includes> tag to tell the file name(s)

Multiples

You need multiple <execution>s with different <id>s for multiple folders:

  <plugin>     <artifactId>maven-resources-plugin</artifactId>     <version>2.6</version>     <executions>       <execution>         <id>copy-resources-1</id>         <phase>validate</phase>         <goals>           <goal>copy-resources</goal>         </goals>         <configuration>           <outputDirectory>${basedir}/target/blah</outputDirectory>           <resources>             <resource>                 <directory>blah</directory>                 <filtering>true</filtering>             </resource>           </resources>         </configuration>       </execution>       <execution>         <id>copy-resources-2</id>         <phase>validate</phase>         <goals>           <goal>copy-resources</goal>         </goals>         <configuration>           <outputDirectory>${basedir}/target/ughh</outputDirectory>           <resources>             <resource>                 <directory>ughh</directory>                 <filtering>true</filtering>             </resource>           </resources>         </configuration>       </execution>     </executions>   </plugin> 
like image 84
Lee Meador Avatar answered Oct 16 '22 18:10

Lee Meador