Search code examples
mavenmaven-archetype

Is it possible to use a maven archetype to prompt for an input during archetype:generate?


I'm exploring the use of maven archetypes to generate a starter project. What I'd like to do is prompt the user for input, and then do something with that answer. I know it's possible to prompt for additional properties using archetype.properties. Is it possible to take the input from these properties and do custom processing of the project structure during project generation?

Specifically what I want to do is include or exclude sample code from a starter project. Some people will want to see a working example and then delete once they're ready to start, while others just want to get started with a blank project.


Solution

  • There are some open issues against the Maven Archetype plugin which (I think) relate to your use case:

    These have been open (and largely inactive) for a long time, so they don't appear to be likely candidates for completion.

    In the absence of built-in support for your use case and assuming there are just two possible outcomes (1. exclude sample code, 2. include sample code) then perhaps you coud provide two archetypes?

    Alternatively, you could provide a single archetype and include a link to sample code (hosted elsewhere, perhaps on GitHub if the sample code is to be freely accesible) in a readme in the root of the generated project.