9

I use Maven 3.0.4 and want to have junit 4 by default.

My projects are created with the command :
$>mvn archetype:create -DgroupId=my.group.id -DartifactId=myArtifactId -DpackageName=my.package.name

This puts a depency to junit version 3.8.1 in the created pom.xml, dispite the fact that verion 4.8.1 is already present.
There are no dependencies to junit in my global settings.xml, and I haven't a local .m2/repository/settings.xml. I don't want to remove the old version 3.8.1., but want that all new projects are created with version 4.8.1

Can I do this in my settings.xml (global or local does not matter)? And if so what is the correct syntax?

kdg1955
  • 305
  • 2
  • 12

1 Answers1

5

A couple things:

archetype:create is deprecated by archetype:generate; please use generate, it's interchangeable with create in your example.

As for a solution, I'd say the simplest thing to do is generate your project, edit the pom to have the correct junit version; and then from within your project run:

mvn archetype:create-from-project 

Which will create an archetype based on your modifications, you simply need to install this with:

cd target/generated-sources/archetype/
mvn install

Now you can create new maven projects with this new archetype as you like with:

mvn archetype:generate -DgroupId=my.group.id -DartifactId=newArtifact -DpackageName=my.package.name -DarchetypeArtifactId=myArtifactId-archetype -DarchetypeGroupId=my.group.id

Hopefully this helps.

Anew
  • 5,175
  • 1
  • 24
  • 36
  • Thanks. Add a first glance rather complex, but it will have reasons. – kdg1955 Jan 24 '13 at 17:08
  • @Anew how to import/use newly created archetype to eclipse? – Abhishek Nayak Feb 14 '14 at 13:35
  • First just tell eclipse where is located your local catalog file. In eclipse : Window => Preference => Maven => Archetypes => 'Add Local Catalog'. The default is $HOME/.m2/archetype-catalog.xml. Apply and it should be visible when you create a new maven project/module. Beware of snapshot versions; maybe you have to check 'include snapshot archetype'. – kdg1955 Mar 13 '14 at 16:18
  • It seems doesn't work for me because it still try to find it online. Any solutions? Thanks. – Tony Sep 18 '14 at 12:46