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);
}