开发者

Generate a random uuid in a maven archetype

开发者 https://www.devze.com 2023-04-09 18:09 出处:网络
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.

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消