有没有一种方法可以对原型产生的项目进行后处理? [英] Is there a way to post-process project generated from archetype?
问题描述
说我有一个原型,我从中生成一个项目.但是我想通过在命令行中传递占位符的值来解决生成时间后生成的项目的属性文件中的占位符.
Say I have an archetype and I generate a project from it. But I would like to resolve placeholders in a property file of the project I generated on after generation time by passing the value for placeholder through command line.
例如具有以下命令行:
mvn原型:create -DarchetypeGroupId = ... -DarchetypeArtifactId = ... -DarchetypeVersion = 1.0 -DgroupId = ... -DartifactId =我的项目-Dversion = 1.0-SNAPSHOT -Dhello = Hello!
mvn archetype:create -DarchetypeGroupId=... -DarchetypeArtifactId=... -DarchetypeVersion=1.0 -DgroupId=... -DartifactId=my-project -Dversion=1.0-SNAPSHOT -Dhello=Hello!
假设原型包含app.properties(作为正在生成的项目的一部分),其内容如下:
say the archetype contains app.properties (as part of project which is being generated) with the following content:
greeting = $ {hello}
greeting=${hello}
是否可以将$ {hello}替换为"Hello!".是在由于mvn archetype:create命令而生成项目之后吗?
Is it possible to replace ${hello} with "Hello!" right after project has been generated as a result of mvn archetype:create command?
推荐答案
是可以的.摘自高级用法指南:Maven原型:>
Yes this is possible. From the advanced usage guide for maven archetypes:
如果用户想进一步定制生成的项目,则可以在src/main/resources/META-INF/中添加一个名为archetype-post-generate.groovy的Groovy脚本.该脚本将最终存储在生成的原型的META-INF文件夹中,并在根据该原型创建项目后执行.该常规脚本可以访问ArchetypeGenerationRequest对象以及用户指定的所有System.getProperties()和所有原型生成属性.
If the user wants to customize the generated project even further, a groovy script named archetype-post-generate.groovy can be added in src/main/resources/META-INF/. This script will end up in the generated archetype's META-INF folder and will be executed upon creating a project from this archetype. This groovy script has access to the ArchetypeGenerationRequest object, as well as all the System.getProperties() and all the archetype generation properties the user has specified.
这篇关于有没有一种方法可以对原型产生的项目进行后处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!