9

i am using maven-assembly plugin to create the zip , how can i rename some files while zipping using the same plugin??

Update:

This is the profile in pom

    <profile>
        <id>D1</id>
        <activation>
            <property>
                <name>D1</name>
                <value>true</value>
            </property>
        </activation>
        <build>
            <plugins>               
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>2.2.2</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                            <configuration>
                                <descriptors>
                                    <descriptor>assembly/online-distribution.D1.xml</descriptor>
                                </descriptors>
                                <appendAssemblyId>false</appendAssemblyId>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>

This is Assembly.xml

<?xml version="1.0" encoding="UTF-8" ?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly- 
    plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<formats>
    <format>tar.gz</format>
</formats>
<id>online</id>
<includeBaseDirectory>false</includeBaseDirectory>
    <dependencySet>
        <outputDirectory>resources</outputDirectory>
        <unpack>true</unpack>
        <includes>
            <include>${project.groupId}:core-config:jar</include>
        </includes>
        <unpackOptions>
            <includes>
            <include>coresrv/env-config.D1.properties</include>
            </includes>
        </unpackOptions>
    </dependencySet>
    <files>
    <file>
        <source>${project.groupId}/core-config.jar/coresrv/env-config.D1.properties</source>
        <outputDirectory>/</outputDirectory>
        <destName>env-config.properties</destName>
    </file>
</files>
</assembly>

i am getting that jar and unpacking it, then renaming a file and zipping it again. Thanks

Sunil Rk
  • 999
  • 6
  • 12
  • 35
  • Can you show the pom file and the descriptor which you are using? – khmarbaise May 14 '13 at 16:18
  • hi, thanks for the reply. i have updated. – Sunil Rk May 15 '13 at 04:59
  • Are you sure your descriptor is correct, cause it looks wrong (dependencySet) without dependencySets. You don't have a warning? Furthermore why don't you use an up-to-date version of the maven-assembly-plugin (2.4). – khmarbaise May 15 '13 at 09:04
  • every thing is working fine except renaming.Is there any way to rename the a file of dependency while unpacking it ?? – Sunil Rk May 15 '13 at 13:14
  • I've got my doubts that there is no error/warning message during the run. But i've given an answer to your question. – khmarbaise May 15 '13 at 13:21
  • I've checked the descriptor and it has errors. The *dependencySet* is **not allowed to be alone** at that level. It must be a child of **dependencySets**. – khmarbaise May 15 '13 at 13:35
  • how can i rename "env-config.D1.properties" to "env-config.properties" in above assembly.xml or in pom.xml ?? – Sunil Rk May 16 '13 at 05:00
  • Doesn't do the destName the trick? If not I would first update the version of maven-assembly-plugin to 2.4 furthermore check the output during the build (WARNINGs!) and recheck the descriptor, cause it produces errors in Eclipse based on XSD checks. Apart from that how do you call the maven-assembly-plugin? – khmarbaise May 16 '13 at 05:14
  • hi again, i got the wt u told..but thing is i am having the dependency called "core-config.jar" that has "env-config.D1.properties".i want to rename that properties file to "env-config.properties". how can i do it ?? (refer assembly.xml) i am trying to rename it through file but not happening.. :( – Sunil Rk May 16 '13 at 11:57
  • is there any maven plugin that can be used for unzipping , then renaming the zipped files and zipping back the dependencies ??(Other than maven assembly and ant plugin) – Sunil Rk May 17 '13 at 05:00

4 Answers4

14

You can use

 <outputFileNameMapping>...</outputFileNameMapping>

which sets the mapping pattern for all dependencies included in this assembly uses

default value:

${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}.
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
3

Answering an old post for posterity... and next time I ask Google and get sent here.

Renaming used to be a pain in Maven, this plugin does what is says on the tin:

copy-rename-maven-plugin

(available in Maven central)

Easy to use:

        <plugin>
            <groupId>com.coderplus.maven.plugins</groupId>
            <artifactId>copy-rename-maven-plugin</artifactId>
            <version>1.0.1</version>
            <executions>
                <execution>
                    <id>copy-properties-file</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <sourceFile>source.props</sourceFile>
                        <destinationFile>destination.properties</destinationFile>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Note: the rename goal will move file(s) in target/

earcam
  • 6,662
  • 4
  • 37
  • 57
2

I faced with same problem, I need to use unpack with renaming some files and as solution we can use two executions of maven-assembly-plugin.

During first execution we will use format dir instead of one of archive formats and will prepare files content and as result will have folder with all needed files.

During second execution we will use folder from previous execution as source in fileSets with files and we will have ability to rename any file using files.file.destName, and as format for second execution we can use archive format like zip to create final archive.

Ivan M.
  • 164
  • 1
  • 1
  • 4
0

You just need to add it in assembly plugin executions like below;

<executions>
 <execution>
  <configuration>
    <finalName>  you can give any name you want  <finalName>
  <configuration>
 </execution>
</executions>
iceberg
  • 1,951
  • 1
  • 22
  • 26
  • You might also need `false`, see https://stackoverflow.com/questions/20697144/can-not-set-the-final-jar-name-with-maven-assembly-plugin – Matthew Oct 24 '22 at 11:01