Conditionally include exclude files while creating project using maven archetype

前端 未结 3 500
温柔的废话
温柔的废话 2021-02-04 10:06

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 pa

3条回答
  •  滥情空心
    2021-02-04 10:36

    I realize that this is a really old question, but now (in 2018), I'm accomplishing this task through the use of Maven's support for a post-generate groovy script.

    If you include a groovy script named "archetype-post-generate.groovy" in the archetype project's src/main/resources/META-INF directory, then it will be executed after the archetype is generated.

    The script will have access to the archetype's properties, e.g. ${artifactId}, including any custom properties.

    What I do is to include all possible files in the archetype, and then in the groovy script, I inspect the relevant archetype properties, and delete the unwanted files.

    In my script, I'm also renaming some files, as well as editing some of the files by reading them in, doing string replacements, and then writing them back out.

    It's a bit cumbersome, but it works.

提交回复
热议问题