Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maven archetype property substitution

Anybody knows is it possible to make substitution for default value of one requredProperty to another in archetype-metadata.xml ?

So, I try to do something like this:

<requiredProperty key="name"/>
<requiredProperty key="groupId">
   <defaultValue>com.mycompamy.${name}</defaultValue>
</requiredProperty>

But when I start to generate project from artifact in interactive mode, maven asks me about groupId property first. But not for name as I expected.

Is it possible to change this behaviour?

like image 320
user1723682 Avatar asked Dec 06 '12 14:12

user1723682


People also ask

What are Maven archetypes?

A Maven archetype is an abstraction of a kind of a project that can be instantiated into a concrete customized Maven project. In short, it's a template project template from which other projects are created.

What is Quickstart archetype in Maven?

maven-archetype-quickstart is an archetype which generates a sample Maven project: project. |-- pom. xml. `-- src.


1 Answers

Your problem is caused by required property loading order. Maven loads every custom required property in alphabetical order. You probably cant change it. But there are 2 ways which will solve your problem:

  1. Renaming ur variables like this:

    "0_name"

    "1_groupId"

    Now it will ask you about name firstly.

  2. Use full maven command, passing only name parameter

    mvn archetype:generate -DarchetypeGroupId=?? -DarchetypeArtifactId=?? -DgroupId=?? -DartifactId=?? -Dversion=?? -Dpackage=?? -Dname=??

    Replace ?? with valid parameters

Hope it will helps you.

EDIT: now i see an asked time. Pretty offtopic but maybe it will help someone else

like image 180
countryroadscat Avatar answered Oct 09 '22 12:10

countryroadscat