Search code examples
mavenmaven-archetype

How to generate custom maven archetype with selected dependencies from the pom?


I am generating a custom archetype using maven. Currently I have three dependencies defined in the pom.xml (dependency 1, dependency 2 and dependency 3).

enter image description here

This is my archetype-metadata.xml file where I have defined the required properties for the archetype generation. Here I have a property called project-type which gets an input 1,2 or 3 and generate the project pom file with based on the entered input value

enter image description here

I just need the pom dependency to be generated based on the 'project-type' property. e.g. - If the project type property is defined as 1, then the pom which generates with the archetype should have only the 'dependency 1'. If the value is 2, only dependency 2 should be included to the pom

Can I do this ? Or should I use 3 pom files here and use each file based on the value type ? or any other ideal solutions to fix this ?

Any help would be really appreciated


Solution

  • You can write if conditions within the pom.xml file based on the defined properties in the archetype-metadata.xml file. Since the name of the property is project-type in here, and then it will generated only the relevant dependencies in the generated archetype template

    enter image description here