【发布时间】:2016-12-14 08:13:42
【问题描述】:
我希望能够从我的原型生成一个项目,其中 其中一个属性默认为空,或者如果在命令行中指定则填充。
这是我的archetype-metadata.xml:
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="basic">
<requiredProperties>
<requiredProperty key="compilerVersion"/>
<requiredProperty key="dependencyClassifier">
<defaultValue></defaultValue>
</requiredProperty>
</requiredProperties>
</archetype-descriptor>
这不起作用。如果dependencyClassifier 中有任何非空白值,那么它可以完美运行。但是,我无法让它在默认值为“空”的情况下工作。
defaultValue 为空/null 时我得到的错误是:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:generate (default-cli) on project standalone-pom: Archetype com.avast.archetype:compile-java:1.0.21 is not configured
[ERROR] Property dependencyClassifier is missing.
[ERROR] -> [Help 1]
或者,我会接受能够在命令行上传递一个空值(或“空白”值)。同样,使用"-DdependencyClassifier= " 不起作用。
如何指定属性默认为空?
谢谢
我想要实现的是能够从包含依赖声明的原型创建项目:
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>artifact</artifactId>
<version>${dependencyVersion}</version>
<classifier>${dependencyClassifier}</classifier>
</dependency>
</dependencies>
并且我需要能够在原型创建时实例化${dependencyClassifier}。这对于${dependencyVersion} 是可能的,因为它永远不会是空的。但是,分类器默认情况下应该为空。
【问题讨论】:
标签: maven maven-3 pom.xml maven-archetype