Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

For example having the following command line:

mvn archetype:create -DarchetypeGroupId=... -DarchetypeArtifactId=... -DarchetypeVersion=1.0 -DgroupId=... -DartifactId=my-project -Dversion=1.0-SNAPSHOT -Dhello=Hello!

say the archetype contains app.properties (as part of project which is being generated) with the following content:

greeting=${hello}

Is it possible to replace ${hello} with "Hello!" right after project has been generated as a result of mvn archetype:create command?

like image 230
Andrey Rikunov Avatar asked Oct 24 '13 11:10

Andrey Rikunov


1 Answers

Yes this is possible. From the advanced usage guide for maven archetypes:

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.

like image 177
Martin Serrano Avatar answered Sep 29 '22 19:09

Martin Serrano