17

我正在组合一个 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 中省略默认值,那么它会提示我输入一个值,但没有默认值。

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

4

6 回答 6

10

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

于 2011-04-13T13:24:42.763 回答
9

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

:
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以使用默认值进行交互式对话框。

于 2010-11-06T22:15:48.070 回答
1

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

于 2012-01-14T03:46:25.477 回答
0

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

e.g. -Dapplication-name="Some Application"
于 2010-10-14T00:15:05.030 回答
0

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

${artifactId.replaceAll(".+", "Some Application")}
于 2022-01-07T22:46:50.293 回答
-3

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

更改</requiredProperty>></requiredProperty>

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

于 2012-03-14T22:15:32.567 回答