【问题标题】:Install tar.gz file in maven repository在 maven 存储库中安装 tar.gz 文件
【发布时间】:2015-11-12 08:42:01
【问题描述】:

我有一个压缩的 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>

如果我将上述命令与 rar 打包一起使用,那么 maven 会上传 XXX-0.0.1-SNAPSHOT.tar.gz 文件,但扩展名为 .rar。

除了为自定义包开发maven插件外,有没有办法将tar.gz上传到maven仓库,然后在其他项目中作为依赖项使用?

(注意:我只想使用 tar.gz 而不是任何其他压缩,例如 rar 等)。

【问题讨论】:

标签: maven tar


【解决方案1】:

@khmarbaise,感谢您的正确指导。使用附加的工件解决了该问题。这是我的 pom.xml 中的一个 sn-p:

<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>

同样可以在其他项目中添加依赖,如下:

<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>

【讨论】:

  • 我正在寻找一种将 rar(资源适配器存档)实际添加到存储库的方法,因为它被打包在我的其他程序集中,这很有帮助。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-02-08
  • 2012-05-20
  • 1970-01-01
  • 1970-01-01
  • 2013-05-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多