gpt4 book ai didi

Maven 原型(prototype) : Modify artifactId

转载 作者:行者123 更新时间:2023-12-01 06:23:58 24 4
gpt4 key购买 nike

在处理项目时,我的要求是创建一个模块。

该命令将类似于:

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 |
+------------------+---------------------------------+

我尝试创建一个新变量为 artifactIdWithUnderscore 通过在 中添加以下条目原型(prototype)元数据.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 的上述值来自archetype项目本身的POM。

选项 3:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${artifactId}.replaceAll("-", "_")</defaultValue>
</requiredProperty>

输出:
test-module.replaceAll("-", "_")

请让我知道如何实现这一目标。

编辑 :

选项 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)

关于Maven 原型(prototype) : Modify artifactId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30593956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com