create POM with junit 4

假如想象 提交于 2019-11-29 18:35:57

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/14505377/create-pom-with-junit-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!