Maven: unpack zip artifact to a SPECIFIC folder name

archmisha picture archmisha · Jan 19, 2012 · Viewed 8.7k times · Source

I am trying to download tomcat zip artifact and unpack it int a folder named tomcat. What i get is tomcat/apache-tomcat-7.0.19/ How can I get rid of the annoying intermediate directory?

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
    <execution>
        <id>unpack-tomcat</id>
        <phase>process-sources</phase>
        <goals>
            <goal>unpack</goal>
        </goals>
        <configuration>
            <artifactItems>
                <artifactItem>
                    <groupId>org.apache</groupId>
                    <artifactId>tomcat</artifactId>
                    <version>7.0.19-win64</version>
                    <type>zip</type>
                    <overWrite>false</overWrite>
                    <outputDirectory>tomcat</outputDirectory>
                    <excludes>webapps/**</excludes>
                </artifactItem>
            </artifactItems>                            
        </configuration>
    </execution>
</executions>
</plugin>

Answer

Shmil The Cat picture Shmil The Cat · Mar 12, 2013

Maybe there is more "mavenish" way for achieving my proposal :) yet using maven ant plugin could be a workaround for your situation :

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <move file   = "tomcat/apache-tomcat-7.0.19/*"
                                      tofile = "tomcat" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <delete dir = "tomcat/apache-tomcat-7.0.19"/>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
</plugin>