Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I conditionally include or exclude a file from an archetype when project is generated?

I'm creating Maven 2 archetypes for our project (Weld). I would like to be able to control which files are placed into the generated project based on the value of a property that is defined during archetype:generate. For instance, I foresee the following prompt:

Define value for groupId: : com.example
Define value for artifactId: : myproject
Define value for package:  com.example: :
Define value for includeGradleSupport: : y

Based on the value of includeGradleSupport, I want to include (or not include) the build.gradle file in the generated project. If the user does not want Gradle support, I don't want to clutter up the generated project with unnecessary files.

Another example is that I might need to provide a Jetty web fragment (to activate a listener perhaps) if the user wants Jetty support.

It's all about customization of the project based on what the developer intends to use. While I could create a whole other archetype, sometimes the changes are so slight that it would be easier to include/exclude a file.

Is there a way to control this behavior using the archetype-metadata.xml descriptor?

like image 736
Dan Allen Avatar asked Dec 17 '09 05:12

Dan Allen


People also ask

How do you know the which archetype an existing Maven project is built on?

Archetype configurationYou can see the packaging maven-archetype . You can customize build of your archetype here as with any other pom. However, there is another pom. xml file located under src\main\resources\archetype-resources which is the pom file of the generated project.

What is archetype selection in Maven?

In short, Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made. The name fits as we are trying to provide a system that provides a consistent means of generating Maven projects.

When making Maven archetype where do you put prototype files?

the prototype files that are copied by the archetype plugin (directory: src/main/resources/archetype-resources/ ) the prototype pom ( pom. xml in: src/main/resources/archetype-resources )

Which Maven plugin is used for archetype generation?

The Archetype Plugin allows the user to create a Maven project from an existing template called an archetype. It also allows the user to create an archetype from an existing project. This plugin requires Java 7.


1 Answers

I personally would move the parts that can be removed/added on user request and put the into different maven profiles so u can build different part using different profiles

like image 74
Mite Mitreski Avatar answered Oct 18 '22 08:10

Mite Mitreski