tvelykyy tvelykyy - 1 year ago 173
Groovy Question

Maven zip artifact copy, unzip and rename

I have a maven module which is packaged as a zip with naming my-artifact-1.0-SNAPSHOT.zip using maven-shade-plugin.

Once the artifact has been installed into local maven repo, I need:


  1. Copy zip to configured local folder.

  2. Unzip archive.

  3. Rename unzipped folder from my-artifact-1.0-SNAPSHOT to my-artifact.



This process should be cross-platform working on Windows, Linux, MacOS machines.

I read that it could be accomplished by using:


  1. maven-dependency-plugin plus another plugin

  2. maven-groovy-plugin



What would the best way to implement such a flow? Any examples are very appreciated.

tom tom
Answer Source

No need for antrun in my opinion, the maven-dependency-plugin should do the trick:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>[your.group.id]</groupId>
                                <artifactId>my-artifact-1.0-SNAPSHOT</artifactId>
                                <version>[your.version]</version>
                                <type>zip</type>
                                <outputDirectory>${project.basedir}/my-artifact/</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Regards,

Tom

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download