31/01/2020

[Maven] Copy files to folder

Similarily to the Maven dependency plugin which copies resources from an artifact to a specific location, we can use Maven resources plugin to copy resources from a folder instead.

 <build>   
   <plugins>   
    <plugin>   
     <groupId>org.apache.maven.plugins</groupId>   
     <artifactId>maven-resources-plugin</artifactId>   
     <version>3.1.0</version>   
      <executions>   
       <execution>   
        <id>YOUR_ID</id>   
        <phase>SOME_PHASE</phase>   
        <goals>   
         <goal>copy-resources</goal>   
        </goals>   
        <configuration>    
         <outputDirectory>some/folder</outputDirectory>  
         <resources>   
          <resource>  
           <directory>some/other/folder</directory>   
          </resource>   
         </resources>   
        </configuration>   
      </execution>   
     </executions>   
    </plugin>   
   </plugins>   
  </build>   


Important parameters are:

  • outputDirectory to set where to copy the resources
  • directory to set from where to copy the resources (you can have multiple resource entries if you need to copy from multiple sources)

No comments:

Post a Comment

With great power comes great responsibility