Renaming a file when creating a zip file through the Maven-assembly plugin

I use the maven-assembly plugin to create a zip , how can I rename some files, and when using zip with 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 get this jar and unpack it, and then rename the file and zip it again. Thanks

+6
source share
3 answers

you can use

  <outputFileNameMapping>...</outputFileNameMapping> 

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

default value:

 ${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}. 
+9
source

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

During the first execution, we will use the dir format instead of one of the archive formats and prepare the contents of the files, and as a result we will get a folder with all the necessary files.

During the second run, we will use the folder from the previous run as a source in fileSets with files , and we will be able to rename any file using files.file.destName , and as the format for the second run we can use the archive format, for example zip to create the final archive.

+2
source

Responding to an old post for posterity ... and next time I ask Google and send it here.

Renaming was a pain in Maven, this plugin does what the tin says:

copy-rename-maven-plugin

(available at Maven Center )

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: target rename will move files to target /

+1
source

Source: https://habr.com/ru/post/944969/


All Articles