Maven 原型:修改 artifactId [英] Maven archetype: Modify artifactId
问题描述
在做项目时,我的要求是创建一个模块.
While working on project, my requirement is to create a module.
命令如下:
mvn archetype:generate \
-DarchetypeCatalog=local \
-DartifactId=test-module
并且目标应该具有以下文件结构
And the target should have following file structure
test-module
|--pom.xml
`--src
`--main
|--install
| `--install.sh
`--scripts
`--test_module.sh
我的整个目标是创建另一个从 artifactId 派生的变量(比如 artifactIdWithUnderscore),用 underscope _
替换所有连字符 -
.这样我就可以使用更新的变量来创建文件.
My whole goal is to create another variable derived from artifactId (say artifactIdWithUnderscore) replacing all hyphens -
by underscope _
. So that I can use the updated variable to create file(s).
示例:
+------------------+---------------------------------+
|INPUT - artifactId|OUTPUT - artifactIdWithUnderscore|
+------------------+---------------------------------+
| test-module | test_module |
| temp | temp |
| test-temp-module | test_temp_module |
+------------------+---------------------------------+
我尝试通过在 archetype-metadata.xml
选项 1:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${StringUtils.replace(${artifactId}, "-", "_")}</defaultValue>
</requiredProperty>
输出:
${StringUtils.replace(${artifactId}, "-", "_")}
选项 2:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${artifactId.replaceAll("-", "_")}</defaultValue>
</requiredProperty>
输出:
maven_archetype_script
上述 artifactId 的值来自于原型项目本身的 POM.
The above value of artifactId is coming from the POM of archetype project itself.
选项 3:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${artifactId}.replaceAll("-", "_")</defaultValue>
</requiredProperty>
输出:
test-module.replaceAll("-", "_")
请告诉我如何实现这一目标.
Please let me know how I can achieve this.
编辑:
选项 4:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${__artifactId__.replaceAll("-", "_")}</defaultValue>
</requiredProperty>
输出:
INFO: Null reference [template 'artifactIdWithUnderscore', line 1, column 1] : ${__artifactId__.replaceAll("-", "_")} cannot be resolved.
Define value for property 'artifactIdWithUnderscore': ${__artifactId__.replaceAll("-", "_")}: :
推荐答案
选项 2 对我有用:
<requiredProperty key="artifactIdWithoutDash">
<defaultValue>${artifactId.replaceAll("-", ".")}</defaultValue>
</requiredProperty>
我可以使用 __artifactIdWithoutDash__.sh 有一个文件名来创建文件(在我的例子中是:some.letters.__artifactIdWithoutDash__.cfg)
I can use __artifactIdWithoutDash__.sh has a file name to create the file (in my case it was: some.letters.__artifactIdWithoutDash__.cfg)
这篇关于Maven 原型:修改 artifactId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!