Am trying to create an archetype which will conditionally include file based on the user input.
Like for eg., if a user will use this custom archetype and pass parameters like
-DprojectType=webProject or -DprojectType=webDBProject
if webProject copy only files related to webProject and if its webDBProject copy files related to webProject and DB related files.
I found out that conditionally include/exclude file is not possible at least in near future using archetype-descriptor.
How do I conditionally include or exclude a file from an archetype when project is generated?
The other option i had was to execute a goal after archetype generation and include/remove unwanted files. But we can't utilize the eclipse M2E plugin with this.
The final option i was trying is to utilize velocity template itself to execute the post processing operations.
Since we can't instantiate an object inside velocity template, I was trying to use reflection to create a file instance and delete some file like the following,
$somestring.getClass().forName("java.io.File").getMethod("delete", null).invoke($somestring.getClass().forName("java.io.File").getConstructor($somestring.getClass()).newInstance("delete.txt"), null)
writing the above line in a velocity template file and running against a standalone velocity java program is running fine. But the same is not working when executing as part of maven archetype generator.
I tried to go step by step, where the execution was successful until getting the class but the getConstructor() part is failing to execute while running archetype:generate.
Did anyone tried and know the reason or have alternate solution?
Also anyone knows what version of velocity engine being used in Maven ?
In case you want to remove a whole directory you can change the example above a little bit in order to achieve that! Here we go:
More archetype-post-generate.groovy examples can be found here and here!