我希望在原型-metadata.xml中为requiredProperty设置一个默认值,以便它基于从命令行传递的另一个属性。说
<requiredProperty key="customProperty">
<defaultValue>${artifactId.toUpperCase()}</defaultValue>
</requiredProperty>但是,当我使用生成的原型生成一个新项目时,并不是项目的artifactId获得了更高的感知,而是原型的artifactId。而当我把它改为
<requiredProperty key="customProperty">
<defaultValue>${artifactId}</defaultValue>
</requiredProperty>我得到了项目的artifactId,正如人们所期望的那样。
是否有一种方法可以根据另一个属性的值为自定义属性分配默认值?
注意:这只发生在交互模式下.
如何复制:
mvn -B archetype:generate -DartifactId=archet -DgroupId=com.example -Dversion=1.0-SNAPSHOT -DarchetypeArtifactId=maven-archetype-archetype由于某种原因,生成了archetype.xml。据我理解,这是一种旧的格式。代之以原型-metadata.xml(为了示例而最小化):
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="basic">
<requiredProperties>
<requiredProperty key="customPropertyUppercased">
<defaultValue>${artifactId.toUpperCase()}</defaultValue>
</requiredProperty>
<requiredProperty key="customProperty">
<defaultValue>${artifactId}</defaultValue>
</requiredProperty>
<!--JUnit version to use in generated project-->
<requiredProperty key="junit-version">
<defaultValue>4.12</defaultValue>
</requiredProperty>
</requiredProperties>
<fileSets>
<fileSet filtered="true" packaged="true">
<directory>src/main/java</directory>
</fileSet>
<fileSet filtered="true" packaged="true">
<directory>src/test/java</directory>
</fileSet>
</fileSets>
</archetype-descriptor>./src/main/resources/archetype-resources/src/main/java/App.java:的模板
package ${groupId}.${artifactId};
/**
${customPropertyUppercased}
${customProperty}
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}使用生成的原型生成一个新项目
mvn archetype:generate -DgroupId=com.example -DartifactId=stacktest -DarchetypeArtifactId=archet -DarchetypeGroupId=com.example -DarchetypeCatalog=local将所有属性设置为默认生成stacktest/src/main/java/com/example/App.java:
package com.example.stacktest;
/**
ARCHET
stacktest
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}因此,customPropertyUppercased是基于原型的artifactId,而customProperty是基于项目的artifactId。
发布于 2018-01-18 19:40:49
这是原型插件中的一个bug,记录在这里:https://issues.apache.org/jira/browse/ARCHETYPE-490
https://stackoverflow.com/questions/40136085
复制相似问题