Generate a random uuid in a maven archetype
I need to create a random UUID and write it to the generated project. Currently, I ask the user to fill in a random UUID each time a project is created, and I would like this to be done automatically.
Right now, I have in my archetype-metadata.xml the following required property:
<requiredProperty key="randomUuid">
<defaultValue>12345678-1234-1234-1234-12345678abcd</defa开发者_如何学编程ultValue>
</requiredProperty>
Then I refer to ${randomUuid}
inside my archetype resources to write this UUID into the generated project.
Any better approach ?
Thanks!
I found myself needing the same thing, so here is what I did to make this work:
<requiredProperty key="testUUID">
<defaultValue>${package.getClass().forName("java.util.UUID").getMethod("randomUUID").invoke(null).toString()}
</defaultValue>
</requiredProperty>
精彩评论