我有一个压缩的 tar.gz 文件,我想将它用作其他项目的依赖项。
我无法使用以下命令将其上传到 maven 存储库中,因为 maven 不支持 tar.gz 打包:
mvn install:install-file -Dfile=/path-to-file/XXX-0.0.1-SNAPSHOT.tar.gz -DpomFile=/path-to-pom/pom.xml
示例 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>
Run Code Online (Sandbox Code Playgroud)
如果我将上述命令与 rar 打包一起使用,那么 maven 会上传 XXX-0.0.1-SNAPSHOT.tar.gz 文件,但扩展名为 .rar。
除了为自定义包开发 maven 插件之外,有没有什么方法可以将 tar.gz 上传到 maven 存储库中,然后在其他项目中作为依赖项使用它?
(注意:我只想使用 tar.gz 而不是任何其他压缩,例如 rar 等)。
@khmarbaise,感谢您的正确指导。使用附加工件解决了该问题。这是我的 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>
Run Code Online (Sandbox Code Playgroud)
类似地,可以在其他项目中添加依赖项,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8409 次 |
最近记录: |