在进行项目时,我的要求是创建一个模块。
该命令将类似于:
mvn archetype:generate \
-DarchetypeCatalog=local \
-DartifactId=test-module
并且目标应该具有以下文件结构
test-module
|--pom.xml
`--src
`--main
|--install
| `--install.sh
`--scripts
`--test_module.sh
我的整个目标是创建另一个从artifactId(例如artifactIdWithUnderscore)派生的变量,替换所有连字符-
通过下视镜_
。这样我就可以使用更新后的变量来创建文件。
例子:
+------------------+---------------------------------+
|INPUT - artifactId|OUTPUT - artifactIdWithUnderscore|
+------------------+---------------------------------+
| test-module | test_module |
| temp | temp |
| test-temp-module | test_temp_module |
+------------------+---------------------------------+
我尝试创建一个新变量带有下划线的artifactId通过添加以下条目原型元数据.xml
选项1:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${StringUtils.replace(${artifactId}, "-", "_")}</defaultValue>
</requiredProperty>
Output:
${StringUtils.replace(${artifactId}, "-", "_")}
选项2:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${artifactId.replaceAll("-", "_")}</defaultValue>
</requiredProperty>
Output:
maven_archetype_script
上述artifactId的值来自archetype项目本身的POM。
选项 3:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${artifactId}.replaceAll("-", "_")</defaultValue>
</requiredProperty>
Output:
test-module.replaceAll("-", "_")
请让我知道如何实现这一目标。
EDIT:
选项 4:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${__artifactId__.replaceAll("-", "_")}</defaultValue>
</requiredProperty>
Output:
INFO: Null reference [template 'artifactIdWithUnderscore', line 1, column 1] : ${__artifactId__.replaceAll("-", "_")} cannot be resolved.
Define value for property 'artifactIdWithUnderscore': ${__artifactId__.replaceAll("-", "_")}: :