Multiple of my Maven projects using maven-assembly-plugin need to copy two binary files into a folder.
These are the two original files common to all of my projects:
procrun.exe
procrunw.exe
I'd like this set of files to be reused. They could come from a dependency such as a JAR or a ZIP file to later unpack them as part of my build process. That way, if I later chose to upgrade the binaries I could create a new version of my common project and just change the dependencies to my common project. Another reason to do this is because I want to use a minimize the number of build-related files in individual projects.
Now, the tricky part is that I need to rename each file while unpacking the dependencies. For instance, for project A, I need the files to be copied as follows:
bin/projectA_procrun.exe
bin/projectA_procrunw.exe
My partial solution is to have these two files in the src/main/build/bin folder on each of the Maven projects.
It's not ideal but at least I'm able to reuse the contents of a common assembly file as described in 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>
The outputFileNameMapping attribute in Assembly allows renaming artifacts but not the files inside the assembly.
One failed attempt consisted in registering each file as an individual Maven artifact. That way, I could use outputFileNameMapping inside sections corresponding to each of my artifacts.
The problem I run into is that Nexus doesn't like having an 'exe' as an artifact.
Any ideas as to how I can achieve the expected result, either by enhancing my partial or by adopting an alternative approach?
You probably won't be able to tell the assembly plugin to unpack-and-rename. But you could use the antrun plugin to rename the files after the assembly plugin had ran.
Your pom will not look pretty after this.
But then again, you're already dealing with custom assemblies, so I'm guessing you're probably willing to accept that :-)
Using outputFileNameMapping specifically doesn't apply to the contents of JAR as you've discovered. You can see this issue for the gory details: MASSEMBLY-312.
This other, fairly old issue: MASSEMBLY-45 proposed an enhancement to allow Ant-style filename mapping which probably would give us the functionality that we need. It was partially implemented but was never finished because of unit testing issues.
I ended up taking khmarbaise's advice and unpacking the files that I needed with the dependencies plugin and then repacking them with assembly.
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