Maven assembly - how to build a JAR project with version included but tar.gz file without artifact?

Using Maven I want to create 1) a JAR file for my current project with the current version included in the filename myproject-version.jar and 2) a generic tar.gzip artifact containing the project JAR file and all dependent JARs in the lib directory and various driver scripts in the bin directory, but without a version number or arbitrary identifier in the name. It works for me using the build plugin, in case I use below pom.xml and assembly.xml then when I run "mvn package" I can get tar.gzip file with JAR and scripts included as desired however I can't seem to fix the naming / version correctly: either I get both a project JAR file and a tar.gzip file with a version number or not depending on the build / finalName used. How can I specify them separately,and is it not possible to build a final artifact without an identifier attached to the artifact name? For example, I would like my project JAR file to be named myproject-0.0.1-SNAPSHOT.jar and the generic "uber" artifact to be named myproject.tar.gz (no version number or additional identifier appended to the name). Is it possible?

Below are my current pom.xml and asssembly.xml.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>mygroup</groupId>
    <artifactId>myproject</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>myproject</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.3</version>
        </dependency>
    </dependencies>

    <build>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/maven/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>    
</project>

      

assembly.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>bin</id>
    <formats>
        <format>tar.gz</format>
    </formats>
    <fileSets>
        <!-- the following file set includes the Python scripts/modules used to drive the monthly processing runs -->
        <fileSet>
            <directory>src/main/python</directory>
            <outputDirectory>bin</outputDirectory>
            <includes>
                <include>indices_processor.py</include>
                <include>concat_timeslices.py</include>
            </includes>
        </fileSet>
        <!-- the following file set includes the JAR artifact built by the package goal -->
        <fileSet>
            <directory>target</directory>
            <outputDirectory>lib</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
    <dependencySets>
        <!-- the following dependency set includes the dependency JARs needed by the main Java executable for indicator processing -->
        <dependencySet>
            <outputDirectory>lib</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <scope>runtime</scope>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>
</assembly> 

      

Thanks in advance for any suggestions.

+3


source to share


2 answers


Just use it ${project.artifactId}

as a value for finalName

in your build config.

Example derived from your config (note the element finalName

inside the config):



        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <descriptors>
                    <descriptor>src/main/maven/assembly.xml</descriptor>
                </descriptors>
                <finalName>${project.artifactId}</finalName>
            </configuration>
            ...
        </plugin>

      

finalName

the default build is used ${project.build.finalName}

unless you change it. The default value for ${project.build.finalName}

is${project.artifactId}-${project.version}

+2


source


I think you are looking for this: http://maven.apache.org/plugins/maven-assembly-plugin/single-mojo.html#finalName just put it in your plugin config. however, I think you should not remove the version if you plan on uploading it to any repository.



+1


source







All Articles