【问题标题】:Install File Using POM instead of commandline使用 POM 代替命令行安装文件
【发布时间】:2017-01-13 06:31:26
【问题描述】:

我目前正在使用:

mvn install:install-file -Dfile={path/to/my/legacy.jar} -DgroupId=horrible -DartifactId=legacy.jar -Dversion=1.2.3 -Dpackaging=jar

将一些旧的遗留 jar 导入我的 repo。这工作得很好,是推荐的方法。似乎这可以通过 POM 而不是我现在使用的命令行 + 脚本来完成。我认为它更干净:

mvn install:install-file

并让我的 repo 存储版本详细信息,而不是将这些信息存储在非 maven 脚本中(这对于 maven 来说很奇怪)。我试图通过设置标签公开这些 -D 设置,但没有奏效。有没有其他人试过这个并让它工作?

【问题讨论】:

  • 也许我没有抓住重点,但你为什么要编写脚本呢?您确定只需要将这些遗留 jar 导入您的存储库一次吗?
  • 只是一个维护工作,如果我们需要再次导出到 repo(无论出于何种原因),我们使用相同的 groupId/版本号导出。

标签: maven


【解决方案1】:

好的,回答我自己的问题:P。您可以通过定义属性来做到这一点,我最初假设 groupId 等被自动导出为属性,但它们不是。

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.whatever</groupId>
  <artifactId>Stuff</artifactId>
  <version>1.2.3</version>

  <description>
  Description of why this horrible jar exists.
  </description>

  <properties> 
    <groupId>${project.groupId}</groupId>
    <artifactId>${project.artifactId}</artifactId>
    <version>${project.version}</version>
    <packaging>${project.packaging}</packaging>
    <file>mylegacy.jar</file>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-install-plugin</artifactId>
        <executions>
          <execution>
            <phase>install</phase>
            <goals>
              <goal>install-file</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

您现在可以使用以下方式安装文件:

mvn install

还有这个 pom.xml。我已经用 maven 3 而不是 2 对此进行了测试。

对于多个文件,另请参阅Maven POM file for installing multiple 3rd party commercial libraries

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2010-10-13
  • 2011-09-15
  • 2018-03-26
  • 2021-12-14
  • 2015-11-02
  • 2023-03-10
  • 2018-12-07
  • 1970-01-01
相关资源
最近更新 更多