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
The project build is on two step. First maven-resources-plugin is used at the copy-resources lifecycle phase to filter the resources located under /src/main and copy them to the target directory. Next, copy-rename-maven-plugin is used to rename the filtered output file file-to-rename. txt to renamed-file.
The Assembly Plugin for Maven enables developers to combine project output into a single distributable archive that also contains dependencies, modules, site documentation, and other files. Your project can easily build distribution "assemblies" using one of the prefabricated assembly descriptors.
Defines the rules for matching and working with files in a given base directory. Absolute or relative from the module's directory. For example, "src/main/bin" would select this subdirectory of the project in which this dependency is defined.
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}.
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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With