Jibby
Jibby

Reputation: 1010

What's the difference between archetype.xml and archetype-metadata.xml in Maven

I'm trying to add additional variables to my archetype. Specifically, my archetype contains a logback.xml file, and I want to populate the log filename with the name of the project I'm generating from the archetype.

I was carrying out the instructions in the answer here Passing extra properties to maven archetype:generate, but it says to add a <requiredProperties> element to my archetype-metadata.xml. My archetype doesn't have an archetype-metadata.xml, it only has an archetype.xml (which was generated automatically when I generated my archetype from maven-archetype-archetype).

In https://maven.apache.org/guides/mini/guide-creating-archetypes.html, Maven refers to archetype.xml as an artifact-descriptor.

I googled archetype-metadata.xml, and found this - http://maven.apache.org/archetype/archetype-models/archetype-descriptor/archetype-descriptor.html. Maven calls it an archetype-descriptor as well, but its specification does not contain the id and resources elements that I see in my archetype.xml.

Are archetype.xml and archetype-metadata.xml the same thing? if not, what are their different purposes? Can I add a <requiredProperties> element to my archetype.xml file? Or should I create an archetype-metadata.xml file?

Upvotes: 10

Views: 2954

Answers (3)

Tiemo Vorsch&#252;tz
Tiemo Vorsch&#252;tz

Reputation: 188

Since there is no answer for the question what the difference is between archetype.xml and archetype-metadata.xml:

As specified in the documentation https://maven.apache.org/archetype/archetype-common/archetype.html archetype.xml was used for schema version 1.0.0. archetype-metadata.xml is used with schema version 1.1.0.

archetype.xml:

Maven's model for the old archetype descriptor (ie for Archetype 1.0.x). The metadata about an archetype is stored in the archetype.xml file located in the META-INF/maven directory of its jar file.

archetype-metadata.xml:

This is a reference for the Archetype descriptor used to describe archetypes's metadata. The metadata about an archetype is stored in the archetype-metadata.xml file located in the META-INF/maven directory of its jar file.

Upvotes: 1

devsprint
devsprint

Reputation: 671

You should create the archetype descriptor (archetype-metadata.xml) as I suggested in the mentioned post, Passing extra properties to maven archetype:generate

Here are the steps that I'm executing to generate the project:

    mkdir temp
    cd temp
    git clone [email protected]:jibbyj/appArchetype.git
    cd appArchetype
    mvn clean install
    mkdir run01
    cd run01
    ls
    mvn archetype:generate \
    -DarchetypeGroupId=com.company.archetype \
    -DarchetypeArtifactId=appArchetype \
    -DarchetypeVersion=1.2-SNAPSHOT \
    -DarchetypeCatalog=local \
    -DinteractiveMode=false \
    -DgroupId=com.company \
    -DartifactId=test \
    -DappName=test

after this flow is completed, in test folder you can find the generated project.

In the pom.xml, the artifactId is set to the "test", also in src/main/resources/logback.xml the substitution is made.

Upvotes: 1

Jibby
Jibby

Reputation: 1010

The main takeaway from the accepted answer above was to use archetype-metadata.xml instead of archetype.xml, with a <requiredProperties> element, as well as a <filesets> element for the resources I want included. In archetype.xml it was a <resources> tag. Also give the archetype a <packaging>maven-archetype</packaging>.

Still not totally clear though what the difference is between archetype.xml and archetype-metadata.xml. Assume archetype.xml is deprecated?

Upvotes: 4

Related Questions