Creating Maven ArcheType . Setting file name

后端 未结 2 1325
忘掉有多难
忘掉有多难 2021-02-13 20:30

I want to create an Archetype in which the user can provide artifactId. Then I want to take this artifactId and create two files.

Here is an ex

相关标签:
2条回答
  • 2021-02-13 20:58

    There is a bug in maven archetype. See bug reports ARCHETYPE-406 and ARCHETYPE-397.

    When fixed it will be possible to define and use custom requiredProperty for your case.

    In archetype-metadata.xml add

    <requiredProperties>
      <requiredProperty key="classPrefix" >
        <defaultValue>
          ${artifactId.substring(0,1).toUpperCase()}${artifactId.substring(1)}
        </defaultValue>
      </requiredProperty>
    </requiredProperties>
    

    Don't forget to add classPrefix to archetype.properties

    0 讨论(0)
  • 2021-02-13 21:04

    I looked through the code that creates the replacement in the filenames of the archetype resources (which can be found here). It seems that the values of the arguments are taken from the context, which means that they are not evaluated. In my opinion, for the moment it is not possible (sad, but true) to use the evaluation mechanism directly in the file names.

    However, by simply implementing the FilesetArchetypeGenerator interface, a good contribution can be made to the archetypes generation.

    0 讨论(0)
提交回复
热议问题