Study on the includebasedirectory of Maven-assembly-plugin

Source: Internet
Author: User
Tags execution

Demand:

This problem has been bothering me for hours, and when I first started using Maven-assembly-plugin to build the tar distribution, I found that every time I finished packing, there was a layer of packaging at the outermost level, like the Artifactid for the tar distribution I was building. Then the final packaged tar file always contains the ABC directory, and then the other subdirectory sub1,sub2. What we want is that when Untar, it's the subdirectory (SUB1,SUB2) that comes straight out, not the form of a subdirectory (/ABC/SUB1,/ABC/SUB2) in the +ABC directory of the ABC directory.

Solution:

In fact, just add the <includeBaseDirectory> element to the assembly.xml and let it be false, as follows:

<assembly>  
      
  <id>tarball</id>  
      
  <formats>  
      
    <format>tar</format>  
      
  </formats>  
      
        
      
  <!--fixed the wrapper folder issue-->  
      
  <includebasedirectory>false</ includebasedirectory>  
      
       
      
  <fileSets>  
      
 ...

For the meaning of this parameter, please refer to Maven-assembly-plugin's official website:

Http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html

In-depth analysis:

Why is this possible, we can study the source code of Maven-assembly-plugin.

First, when we use Maven-assembly-plugin in Pom.xml and the location of the Assembly.xml file is configured in <descriptor>:

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactid>mav  
                                   En-assembly-plugin</artifactid> <version>2.2.1</version> <configuration> <appendassemblyid>fal  
                                                    Se</appendassemblyid> <descriptors>  
                                            <descriptor>src/main/assembly/assembly.xml</descriptor>  
                                   </descriptors> </configuration>  
                                               <executions> <execution>     <id>make-assembly</id> <phase>package</pha  
                                                             Se> <goals>  
                                            <goal>single</goal> </goals>  
                          </execution> </executions> </plugin> ... </plugins> < /build>

The plug-in will call the Defaultassemblyreader Readassemblies () method and invoke the following code to traverse the <descriptors> element:

for (int i = 0; i < descriptors.length i++) 
          { 
              GetLogger (). info ("Reading Assembly Descriptor:" + Descriptor S[i]); 
              Addassemblyfromdescriptor (Descriptors[i], locator, ConfigSource, assemblies); 
          } 
      

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.