mavenmaven-assembly-pluginrpm-maven-plugin

How to prevent maven assembly plugin from renaming artifacts


In my maven project I have to a (fairly large amount) of RPMs. For convenience during deployment I want to assemble all the RPMs into a single archive (.tar.gz). The assembly runs in a separate module which depends on all the RPM modules.

For this I have the following assembly.xml:

<?xml version="1.0"?>
<assembly>
    <id>myproject-rpm-package</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <baseDirectory>${project.parent.parent.name}-${project.version}-rpms</baseDirectory>

    <dependencySets>
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <includes>
                <!-- Include only the RPMs -->
                <include>*:rpm</include>
            </includes>
            <outputDirectory>/</outputDirectory>
        </dependencySet>
    </dependencySets>
</assembly>

This works well, but it renames all my RPMS to follow the format: <projectname>-<version>.rpm. Losing useful properties in the RPM naming convention: <rpm name>-<version>-<release>.noarch.rpm. The RPMS still work fine.

My suspicion is that this comes from the maven assembly property outputFileNameMapping.

Is my assumption correct? If so, how can I prevent the renaming of my RPM files by the assembly plugin?


Solution

  • Your assumption is correct. The maven-assembly-plugin will rename all the dependencies of your assembly project into the format specified by outputFileNameMapping:

    Sets the mapping pattern for all dependencies included in this assembly. Default value is: ${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension}.

    The documentation contains all values that you can specify in this attribute:

    Which properties can be used in the outputFileNameMapping parameter.

    You can use :

    • all system or maven properties available in your build with the syntax ${myProperty}.
    • all environment variables with ${env.XXX} where XXX is the environment variable.
    • the special ${dashClassifier?} property (see above).
    • all artifacts attributes ( from the Artifact class) like :
      • ${artifact.groupId} : The artifact groupId.
      • ${artifact.artifactId} : The artifact artifactId.
      • ${artifact.version} : The artifact classifier.
      • ${artifact.baseVersion} : The artifact base version (For a SNAPSHOT it will be always -SNAPSHOT and not its timestamp even if you didn't built it yourself).
      • ${artifact.classifier} : The artifact classifier.
      • ${artifact.scope} : The artifact scope.
      • ...

    You can use ${module.XXXXX} when using it for your project modules artifacts.

    It looks like it is missing from the documentation, but starting from version 2.2, you can also use the ${artifact.properties.*} property, as mentioned in the JIRA MASSEMBLY-498. This will reference custom properties you have set in this artifact inside the <properties> element.

    So, for example, you could have:

    <outputFileNameMapping>${artifact.artifactId}-${artifact.version}.noarch.rpm</outputFileNameMapping>
    

    Note that the plugin will always rename the files based on that pattern. There is no option to skip the renaming.