【问题标题】:Ask for maven archetype properties with defaults询问具有默认值的 Maven 原型属性
【发布时间】:2010-10-09 00:27:26
【问题描述】:

我正在组合一个 maven 原型,它有一堆用于过滤各种原型资源的自定义属性。我在 archetype-metadata.xml 中指定了这些默认值,例如

<requiredProperties>
  <requiredProperty key="application-name">
    <defaultValue>Some Application</defaultValue>
  </requiredProperty>>  
</requiredProperties>

但是,当我尝试使用原型创建项目时,它不允许我以交互方式更改这些。例如,它要求默认版本如下

Define value for property 'version': 1.0-SNAPSHOT: 

允许输入版本,但如果没有输入则默认为 1.0-SNAPSHOT。对于我的自定义属性,它只是在创建新项目之前显示它们

[INFO] Using property: application-name = Some Application

如果我从 archetype-metadata.xml 中省略默认值,那么它会提示我输入一个值,但没有默认值。

是否可以提供默认值并仍然得到提示?

【问题讨论】:

    标签: maven-2 maven-archetype


    【解决方案1】:

    简而言之,不,这是不可能的。 这有一个JIRA 问题。 如果这对您来说是个问题,您可能想投票给它。

    【讨论】:

      【解决方案2】:

      请寻找最后一个问题来提交设置。就我而言,还有最后一个问题:

      :
      Confirm properties configuration:
      groupId: ....
       Y: :
      

      如果我输入 n ,那么所有属性都将与我在 archetype-metadata.xml 中的默认值进行交互。

      这是我的控制台部分:

      Choose archetype:
      1: file:///C:\Aktentasche\_daten\m3 -> maven-dsl-project-archet...
      Choose a number: : 1
      Downloading: file:///C:\Aktentasche\_daten\m3/net/sf/maven/plug...
      data.xml
      [INFO] Using property: groupId = net.sf.maven.plugins
      [INFO] Using property: artifactId = dslexample
      [INFO] Using property: version = 1.0.0-SNAPSHOT
      [INFO] Using property: package = net.sf.maven.plugins
      [INFO] Using property: eclipse_platform = helios
      [INFO] Using property: tycho_version = 0.8.0
      Confirm properties configuration:
      groupId: net.sf.maven.plugins
      artifactId: dslexample
      version: 1.0.0-SNAPSHOT
      package: net.sf.maven.plugins
      eclipse_platform: helios
      tycho_version: 0.8.0
       Y: :
      

      这里我必须输入 n 进行默认的交互式对话框。

      【讨论】:

        【解决方案3】:

        我知道这远非理想,但如果您为所有 requiredProperty(包括 groupId、artifactId、version 和 package)提供默认值,您将收到简历,然后输入 n你会实现你的目标

        【讨论】:

          【解决方案4】:

          我在 Maven 邮件列表中提出了这个问题,但没有得到回复。同时,作为一种解决方法,可以在运行原型时使用系统属性在命令行中覆盖它们

          e.g. -Dapplication-name="Some Application"
          

          【讨论】:

            【解决方案5】:

            我一直在使用这个 hack,不确定它是否是最好的方法,但这是我迄今为止发现的唯一方法:

            ${artifactId.replaceAll(".+", "Some Application")}
            

            【讨论】:

            • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
            【解决方案6】:

            你试过从结尾requiredProperty 中去掉第二克拉吗?

            &lt;/requiredProperty&gt;&gt; 更改为&lt;/requiredProperty&gt;

            看起来可能是格式错误的 XML 问题。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2016-12-14
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2013-10-17
              相关资源
              最近更新 更多