Pages

21/09/2019

[Maven] Copy specific files from artifact in local directory

With Maven dependency plugin, it is possible to unpack certain content from specific artifacts in a desired directory during a certain phase:

 <build>  
   <plugins>  
     <plugin>  
       <groupId>org.apache.maven.plugins</groupId>  
       <artifactId>maven-dependency-plugin</artifactId>  
       <version>3.1.1</version>  
         <executions>  
           <execution>  
             <id>YOUR_ID</id>  
             <phase>SOME_PHASE</phase>  
             <goals>  
               <goal>unpack</goal>  
             </goals>  
             <configuration>  
               <artifactItems>  
                 <artifactItem>  
                   <groupId>SOME_GROUP</groupId>  
                   <artifactId>SOME_ARTIFACT</artifactId>  
                   <version>SOME_VERSION</version>  
                   <type>SOME_TYPE</type>  
                   <overWrite>true</overWrite>  
                   <outputDirectory>some/folder</outputDirectory>  
                   <includes>some/pattern/**,and/another/pattern/**</includes>  
                 </artifactItem>  
               </artifactItems>  
             </configuration>  
         </execution>  
       </executions>  
     </plugin>  
   </plugins>  
 </build>  


Important parameters are:

  • artifactItem to ONLY consider that artifact instead of ALL imported ones
  • type to specify the artifact type, eg: jar
  • overWrite to specify whether to overwrite existing files in output folder
  • outputDirectory to specify where to unpack the content
  • includes to limit unpacking ONLY to specific files and folders. Multiple patterns can be added by separating with a comma

No comments:

Post a Comment

With great power comes great responsibility