Maven build: rename the unzipped file

Several of my Maven projects using maven-assembly-plugin should copy two binaries to a folder.

These are two original files that are common to all my projects:

procrun.exe

procrunw.exe

I would like this set of files to be reused. They can come from a dependency, such as a JAR or ZIP file, to subsequently unzip them as part of my build process. That way, if I later decided to update the binaries, I could create a new version of my shared project and just change the dependencies to my shared project. Another reason for this is because I want to use minimization of the number of files associated with building files in individual projects.

Now the tricky part is that I need to rename each file when unpacking the dependencies . For example, for project A, I need files that need to be copied as follows:

bin / projectA_procrun.exe

bin / projectA_procrunw.exe

Partial solution

My partial solution is to have these two files in the src / main / build / bin folder for each of the Maven projects .

This is not ideal, but at least I can reuse the contents of the shared assembly file as described on this page :

<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"> <id>my_assembly</id> <formats> <format>zip</format> </formats> <files> <file> <source>src/main/build/bin/procrun.exe</source> <outputDirectory>bin</outputDirectory> <destName>${myexecutable.name}.exe</destName> </file> <file> <source>src/main/build/bin/procrunw.exe</source> <outputDirectory>bin</outputDirectory> <destName>${myexecutable.name}w.exe</destName> </file> </files> <!-- Additional details ommitted --> </assembly> 

Unsuccessful attempt

The outputFileNameMapping attribute in Assembly allows you to rename artifacts, but not files within the assembly.

One unsuccessful attempt was to register each file as a separate Maven artifact. That way I could use outputFileNameMapping inside the sections corresponding to each of my artifacts.

The problem I am facing is that Nexus does not like to have "exe" as an artifact.

Question

Any ideas on how I can achieve the expected result, either by improving my partial, or by adopting an alternative approach?

+4
source share
2 answers

You probably won't be able to tell the assembly plugin to unpack and rename. But you can use the antrun plugin to rename files after running the build plugin.

After that, your pom will not look beautiful.

But then again, you are already dealing with custom assemblies, so I assume that you will probably agree that :-)

+3
source

Using outputFileNameMapping does not specifically apply to JAR content, as you have discovered. You can see this problem for gory details: MASSEMBLY-312 .

This is another, rather old problem: MASSEMBLY-45 proposed an enhancement that allowed us to map Ant file names, which would probably give us what we need. It was partially implemented, but was never completed due to problems with unit testing.

In the end, I got khmarbaise advice and unpacked the files I needed with the dependency plugins, and then repacked them using the build.

+1
source

All Articles