开发者

Maven project created from Old (1.x) Archetype

I'm trying to learn Maven following this Getting Started Guide.

I've Apache Maven 3.0.1 on Linux. I've issued the following command to create a first project:

yes | mvn archetype:generate \
  -DarchetypeGroupId=org.apache.开发者_如何学运维maven.archetypes \
  -DarchetypeArtifactId=maven-archetype-quickstart \
  -DgroupId=org.obliquid.helpers \
  -DartifactId=obliquid-helpers \
  -Dversion=0.1

However, in the output I read:

[INFO] project created from Old (1.x) Archetype in dir: ...

How can I use a current version for the Archetype? Is the guide that I'm reading outdated?

As a sub-question, I've noticed that in the pom.xml mentions junit version 3.8.1, while I'd like to use junit version 4.8.x - How to change that? I can just change the version number in the XML?

Is there a better guide or book that you can suggest?


The version you are using as well as the guide you are referring is current enough. You can ignore the message. The project that is created does work fine with the latest maven.

As for junit, you can change the version of the dependency appropriately. The project that is created using archetype:generate is only an indicative one, which is meant to be customized.

In addition to what you are looking at, you could also look Maven: The Complete Reference


If you include -DinteractiveMode=true in your mvn archetype:generate command:

mvn archetype:generate \
    -DgroupId=org.obliquid.helpers \
    -DartifactId=obliquid-helpers \
    -Dversion=0.1 \
    -DinteractiveMode=true

you are presented with a (large) catalog of available mvn archetypes, along with a brief description of each.

Currently, a couple of the best simple Java app archetypes in that list are:

1844: remote -> org.spilth:java9-minimalist-quickstart

and

1966: remote -> pl.org.miki:java8-quickstart-archetype

The second one includes a test scope that uses JUnit version 4.11 for unit-tests. To use that archetype you just need to specify the archetypeGroupId and archetypeArtifactId as in:

mvn archetype:generate \
    -DarchetypeGroupId=pl.org.miki \
    -DarchetypeArtifactId=java8-quickstart-archetype \
    -DgroupId=org.obliquid.helpers \
    -DartifactId=obliquid-helpers \
    -Dversion=0.1

For some reason mvn archetype:generate assumes archetypeVersion=1.0 even when the archetype metadata indicates a different version for the latest/release.

To specify an archetype version besides 1.0 you just need to define a value for the archetypeVersion property, e.g.

mvn archetype:generate \
    -DarchetypeGroupId=org.apache.maven.archetypes \
    -DarchetypeArtifactId=maven-archetype-quickstart \
    -DarchetypeVersion=1.1 \
    -DgroupId=org.obliquid.helpers \
    -DartifactId=obliquid-helpers \
    -Dversion=0.1 \
    -DinteractiveMode=true

Find out what versions are available by visiting https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/ with a web browser.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜