【问题标题】:Generic pom.xml for building an executable jar: How can I specify dependency groupId/artifactId/version at runtime?用于构建可执行 jar 的通用 pom.xml:如何在运行时指定依赖项 groupId/artifactId/version?
【发布时间】:2012-02-13 06:13:24
【问题描述】:

我有一种情况,我们在 Eclipse 中使用 Maven,最终得到了许多包含要部署代码的工件。效果很好。

我们的一个目标平台在一个非常特定的位置调用一个明确命名的可执行 jar,经过一些试验,我发现可以通过 new pom 创建一个合适的可运行 jar。 xml 仅取决于从 Eclipse 项目创建的工件,然后调用第一个复制依赖项以从工件中获取依赖项,然后在正确的位置创建一个空 jar,但在清单中正确设置了 Main-Class 和 Class-Path .

这适用于我们的测试项目,但现在我想概括它,所以我需要能够提供 groupId/artifactId/version 以便在调用时部署工件。

我已经尝试过 properties-maven-plugin 之类的

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-2</version>
    <executions>
      <execution>
        <phase>initialize</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
        <file>foobar.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

期待

  <dependencies>
    <dependency>
      <groupId>${artifact.groupId}</groupId>
      <artifactId>${artifact.artifactId}</artifactId>
      <version>${artifact.version}</version>
    </dependency>
  </dependencies>

要正确填写。不幸的是 Maven 抱怨:

[ERROR]     'dependencies.dependency.artifactId' for ${artifact.groupId}:${artifact.artifactId}:jar with value '${artifact.artifactId}' does not match a valid id pattern. @ line 85, column 19
[ERROR]     'dependencies.dependency.groupId' for ${artifact.groupId}:${artifact.artifactId}:jar with value '${artifact.groupId}' does not match a valid id pattern. @ line 84, column 16
[ERROR]     'dependencies.dependency.version' for ${artifact.groupId}:${artifact.artifactId}:jar must be a valid version but is '${artifact.version}'. @ line 86, column 16

只会有那个单一的依赖关系。我怎样才能实现我想要的?

【问题讨论】:

    标签: java maven properties


    【解决方案1】:

    不要这样做。使用 maven-archetype-plugin 制作一个模板,每次都会剔除新项目。

    【讨论】:

    • 我不喜欢 pom.xml 每次都是新的想法,但我喜欢 pom.xml 是完整的(而不是依赖于未包含的属性)。我已经完成了这项工作。其他人请注意:不要在您的模板变量中包含句点。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 2013-02-11
    • 2015-05-24
    • 1970-01-01
    相关资源
    最近更新 更多