2
votes

I have a compressed tar.gz file and I want use it as dependency for other projects.

I am unable upload it in maven repository with the following command because maven doesn't support tar.gz packaging :

mvn install:install-file -Dfile=/path-to-file/XXX-0.0.1-SNAPSHOT.tar.gz -DpomFile=/path-to-pom/pom.xml

Sample pom.xml

<project>

  <modelVersion>4.0.0</modelVersion>
  <name>XXX</name>
  <groupId>com.example.file</groupId>
  <artifactId>xxx</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>tar.gz</packaging>

</project>

If I use the above mentioned command with rar packaging then maven does upload XXX-0.0.1-SNAPSHOT.tar.gz file but with .rar extension.

Beside developing maven plugin for custom package, is there any way to upload tar.gz in maven repository and later use it in other project as dependency?

(Note: I just want to use tar.gz and not any other compression e.g rar, etc).

1
Only possible as an attached artifact not as main artifact. Apart from that. Where does the tar.gz package come from? Maven build?khmarbaise

1 Answers

5
votes

@khmarbaise, thanks you guided correctly. The problem is solved using attached artifact. Here is a snippet from my pom.xml :

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.mojo</groupId>
      <artifactId>build-helper-maven-plugin</artifactId>
      <version>1.7</version>
      <extensions>true</extensions>
      <executions>
        <execution>
          <id>attach-artifacts</id>
          <phase>package</phase>
          <goals>
            <goal>attach-artifact</goal>
          </goals>
          <configuration>
            <artifacts>
              <artifact>
                <file>xxx-0.0.1-SNAPSHOT.tar.gz</file>
                <type>tar.gz</type>
                <classifier>optional</classifier>
              </artifact>
            </artifacts>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Similarly the dependency can be added in other project as follows:

<dependencies>
    <dependency>
     <groupId>your.group.id</groupId>
     <artifactId>xxx</artifactId>
     <version>0.0.1-SNAPSHOT</version>
     <classifier>optional</classifier>
     <type>tar.gz</type>
    </dependency>
  </dependencies>