Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven rename a file after everything else finishes

Tags:

maven

ant

I have a project which I need to rename the final output file generated by the Maven Assembly Plugin after everything else finishes (in the compiling/building/assembly process).

The Maven Assembly Plugin is generating a final .zip file, based on the project's name, and I need to rename this completely to final-version.oxt. I'm trying to use the maven-antrun-plugin to rename it, as pointed by other similar questions here, but no luck (I've never used Maven or Ant before, so maybe I'm missing something).

This is the <build> section of the project's pom.xml. The rename part seems to be completely ignored, since no file is generated in my home folder.

<build>
    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <executions>
                <execution>
                    <id>assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>attached</goal>
                    </goals>
                    <configuration>
                        <archive>
                            <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>
                        </archive>
                        <descriptors>
                            <descriptor>src/main/assembly/ooo-jar.xml</descriptor>
                            <descriptor>src/main/assembly/ooo.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
                <execution>
                    <phase>deploy</phase>

                    <configuration>
                        <tasks>
                            <copy file="${project.build.directory}/target/libreofficeplugin-ooo.zip"
                             tofile="/home/brunofinger/final-version.oxt" />
                        </tasks>
                    </configuration>
                </execution>
            </executions>
        </plugin>

    </plugins>
</build>
like image 280
Bruno Finger Avatar asked Dec 23 '13 10:12

Bruno Finger


1 Answers

A few modifications made it work, probably the phase was wrong, but using <phase>install</phase> seems to make it work:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>install</phase>

                    <configuration>
                        <target>
                            <copy file="${project.build.directory}/libreofficeplugin-ooo.zip" tofile="${project.build.directory}/final-version.oxt" />
                        </target>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
like image 177
Bruno Finger Avatar answered Sep 17 '22 16:09

Bruno Finger