Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven assembly descriptor properties

I want to pack two or more very similar distributions, the only difference is path to data set that will be inside those distributions.

Given this example for path: ${project.basedir}/src/config/dataset1

<?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">

    <id>dataset1</id>
    <formats>
        <format>zip</format>
    </formats>

    <fileSets>
        <fileSet>
            <directory>${project.basedir}/src/config/dataset1/aaa</directory>
            <outputDirectory>conf/aaa</outputDirectory>
        </fileSet>
        <fileSet>
            <directory>${project.basedir}/src/config/dataset1/bbb</directory>
            <outputDirectory>conf/bbb</outputDirectory>
        </fileSet>
    </fileSets>

    <!-- MANY MORE FILESETS... -->

</assembly>

Now I want exactly the same assembly descriptor for different data set, for example: ${project.basedir}/src/config/dataset2

Off course I could create two assembly descriptors. But then again I would have to keep in mind to change multiple places when needed, or worse when adding another dataset or two.

Is there a way how solve this, like creating multiple executions and passing properties to it? Or something ever nicer?

EDIT: This wish item would solve everything: https://jira.codehaus.org/browse/MASSEMBLY-445

like image 222
vehovmar Avatar asked Apr 29 '15 12:04

vehovmar


People also ask

What is assembly descriptor in Maven?

This descriptor specifies the type of assembly archive to create, the contents of the assembly, and the ways in which dependencies or its modules are bundled with an assembly. <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

What is fileset in Maven?

Defines the rules for matching and working with files in a given base directory.

How does Maven Assembly plugin work?

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.

What is goal single in Maven?

This goal is suitable either for binding to the lifecycle or calling directly from the command line (provided all required files are available before the build starts, or are produced by another goal specified before this one on the command line).


1 Answers

Yes, you could use properties for this.

  1. Create properties (with default value) for parts that differs between executions in pom.xml. E.g.:
<properties>
    <dataset.dir>config/dataset</dataset.dir>
</properties>
  1. Use them in your assembly descriptor just like any other property (e.g ${project.basedir} )

  2. For different executions you could:

    • use several build profiles (Maven profiles) where override property value;

    • or pass values directly as a mvn call argument (like mvn package -Dprop=val)

Also, if you want to use these properties in any other place, you could populate them via placeholders in any config by using other maven plugins (for instance, maven-resource-plugin).

like image 153
arghtype Avatar answered Oct 17 '22 01:10

arghtype