Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create POM with junit 4

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?

like image 709
kdg1955 Avatar asked Jan 24 '13 15:01

kdg1955


1 Answers

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.

like image 52
Anew Avatar answered Dec 03 '22 02:12

Anew