Maven best practice for creating ad hoc zip artifact

Decide what classifier you will use for your zip file, for sake of argument let's say it would be sample.

In your project create file assembly/sample.xml

Fill in assembly/sample.xml with something like this:

<?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>sample</id>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <outputDirectory>/</outputDirectory>
      <directory>some/directory/in/your/project</directory>
    </fileSet>
  </fileSets>
  <!-- use this section if you want to package dependencies -->
  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>
      <excludes>
        <exclude>*:pom</exclude>
      </excludes>
      <useStrictFiltering>true</useStrictFiltering>
      <useProjectArtifact>false</useProjectArtifact>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>

Add this to your pom's build section

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>create-distribution</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <descriptors>
                <descriptor>assembly/sample.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

As a result it should create and install you-project-name-VERSION-sample.zip.

I suggest you read chapter on assemblies from Sonatype's maven book: https://books.sonatype.com/mvnref-book/reference/assemblies.html

Also, read assembly format specification: http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html


Fill in assembly/sample.xml with something like this:

<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>install</id>
  <baseDirectory>/</baseDirectory>
  <formats>
  <format>zip</format>
</formats>
<fileSets>
  <fileSet>
    <includes>
      <include>README*</include>
      <include>*.sh</include>
    </includes>
  </fileSet>
  <fileSet>
    <directory>target/classes/</directory>
    <outputDirectory>resources</outputDirectory>
    <includes>
      <include>*.properties</include>
       <include>*.xml</include>
    </includes>
    <lineEnding>dos</lineEnding>
  </fileSet>
  <!-- 
  <fileSet>
    <directory>target/</directory>
    <outputDirectory>lib</outputDirectory>
    <includes>
      <include>*.jar</include>
    </includes>
    <lineEnding>dos</lineEnding>
  </fileSet>
   -->
</fileSets>
 <!-- use this section if you want to package dependencies -->
  <dependencySets>
    <dependencySet>
      <outputDirectory>lib</outputDirectory>
      <excludes>
        <exclude>*:pom</exclude>
      </excludes>
      <useStrictFiltering>true</useStrictFiltering>
      <useProjectArtifact>true</useProjectArtifact>
      <scope>runtime</scope>
    </dependencySet>
  </dependencySets>
</assembly>

add below codes in pom.xml file.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptor>assembly/sample.xml</descriptor>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

run commands as mvn package -P dev -Dmaven.test.skip

will create the zip files that include : xxxx.zip -lib/.jar -resources/.xml/properties -readme -start.sh