Maven rename a file after everything else finishes

后端 未结 3 1144
花落未央
花落未央 2021-01-04 03:24

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/a

相关标签:
3条回答
  • 2021-01-04 04:04

    You don't need to use antrun to rename the output file. Just use the tag finalName of the assembly plugin to rename the output file.

    <?xml version="1.0" encoding="UTF-8"?>
    <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>
                <finalName>final-version.oxt</finalName>
             </configuration>
          </execution>
       </executions>
    </plugin>
    
    0 讨论(0)
  • 2021-01-04 04:07

    This question is nearly an year old, but in case anyone else is facing similar issue, here is an alternate solution.

    If you are looking for a more mavenish way of doing it,you can use

     <plugin>
        <groupId>com.coderplus.maven.plugins</groupId>
        <artifactId>copy-rename-maven-plugin</artifactId>
        <version>1.0.1</version>
        <executions>
          <execution>
            <id>rename-file</id>
            <phase>install</phase>
            <goals>
              <goal>rename</goal>
            </goals>
            <configuration>
              <sourceFile>${project.build.outputDirectory}/libreofficeplugin-ooo.zip</sourceFile>
              <destinationFile>${project.build.outputDirectory}/final-version.oxt</destinationFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    

    and in case you want to copy instead of rename, use the copy goal instead of the rename goal.

    0 讨论(0)
  • 2021-01-04 04:15

    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>
    
    0 讨论(0)
提交回复
热议问题