mavenmaven-3maven-deploy-plugin

creating a tar archive from maven deploy


I am trying to use maven v3 to create a tar.gz output for a non-Java project in order to deploy to nexus. I cannot specify tar in the packaging option in my pom file. Unless mistaken, I can specify tar as an option for packaging when running mvn deploy. Is there anyway I can specify that in the pom file itself?


Solution

  • You can create the TAR.GZ file and "attach" it to the primary artifact. I have an example to repackage a WAR into Linux service on GitHub. The key steps are to package the assembly:

    <project ...>
        ...
      <build>
        <pluginManagement>
          <plugins>
            ...
            <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-assembly-plugin</artifactId>
              <executions>
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>single</goal>
                  </goals>
                </execution>
              </executions>
              <configuration>
                <attach>true</attach>
                <formats>
                  <format>tar.gz</format>
                </formats>
                <descriptorSourceDirectory>src/main/assemblies</descriptorSourceDirectory>
              </configuration>
            </plugin>
            ...
          </plugins>
        </pluginManagement>
        <plugins>
          ...
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
          </plugin>
          ...
        </plugins>
      </build>
    </project>
    

    <attach>true</attach> installs the artifact. The assembly in this case is:

    <?xml version="1.0" encoding="UTF-8"?>
    <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0
                          http://maven.apache.org/xsd/assembly-2.0.0.xsd">
      <id>bin</id>
      <baseDirectory>${artifactId}-${version}</baseDirectory>
      <files>
        <file>
          <outputDirectory>bin</outputDirectory>
          <source>
            ${project.build.directory}/${project.build.finalName}.jar
          </source>
          <filtered>false</filtered>
          <destName>${artifactId}.jar</destName>
        </file>
      </files>
      <fileSets>
        <fileSet>
          <outputDirectory>bin</outputDirectory>
          <directory>${project.basedir}/src/bin</directory>
          <includes>
            <include>${artifactId}.conf</include>
          </includes>
          <filtered>true</filtered>
        </fileSet>
      </fileSets>
      <dependencySets>
        <dependencySet>
          <outputDirectory>lib</outputDirectory>
          <useProjectArtifact>false</useProjectArtifact>
          <includes>
            <include>*:*-x86_64:*</include>
          </includes>
          <scope>runtime</scope>
          <outputFileNameMapping>
            lib${artifact.artifactId}.${artifact.type}
          </outputFileNameMapping>
        </dependencySet>
      </dependencySets>
    </assembly>
    

    but you'll need to find/create one appropriate for your use-case.