3
在處理項目時,我的要求是創建一個模塊。Maven原型:修改artifactId
該命令會像:
mvn archetype:generate \
-DarchetypeCatalog=local \
-DartifactId=test-module
而且目標應具有以下文件結構
test-module
|--pom.xml
`--src
`--main
|--install
| `--install.sh
`--scripts
`--test_module.sh
我的整個目標是創建的artifactId(比如artifactIdWithUnderscore)衍生的另一個變量替換所有連字符。 -
by underscope _
。這樣我可以使用更新的變量來創建文件。
實施例:
+------------------+---------------------------------+
|INPUT - artifactId|OUTPUT - artifactIdWithUnderscore|
+------------------+---------------------------------+
| test-module | test_module |
| temp | temp |
| test-temp-module | test_temp_module |
+------------------+---------------------------------+
我試圖通過在原型-metadata.xml中加入以下條目
選項1創建一個新的變量作爲artifactIdWithUnderscore:
<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到來。
方案3:
<requiredProperty key="artifactIdWithUnderscore" >
<defaultValue>${artifactId}.replaceAll("-", "_")</defaultValue>
</requiredProperty>
輸出:
test-module.replaceAll("-", "_")
請讓我知道我能做到這一點。
EDIT:
選項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("-", "_")}: :
你能告訴我們你的'archetype.properties'文件? –
@MattEckert,我沒有'archetype.properties'文件。使用'archetype-metadata。xml'。 – Ambrish