Java 如何配置 maven 在新项目中添加 junit 4.10 而不是 3.8 依赖项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21777087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to configure maven to add junit 4.10 instead of 3.8 dependency in new project
提问by Abhishek Nayak
When i am creating a new maven project in eclipse kepler, eclipse automatically adds junit 3.8 dependency in pom.xml like
当我在 eclipse kepler 中创建一个新的 maven 项目时,eclipse 会自动在 pom.xml 中添加 junit 3.8 依赖项,如
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8</version>
<scope>test</scope>
</dependency>
I want to be available newer version like: 4.10,
我想提供更新的版本,例如:4.10,
Where can i configure to use newer version instead of old?
我在哪里可以配置使用新版本而不是旧版本?
采纳答案by Franti?ek Hartman
The junit version is described in archetype that is used to create maven project.
junit 版本在用于创建 maven 项目的原型中进行了描述。
You need to either find archetype that will fit your needs, or create your own.
您需要找到适合您需求的原型,或者创建您自己的.
Then once you have it you need to select to use this archetype when creating the project in Eclipse.
然后,一旦你有了它,你就需要在 Eclipse 中创建项目时选择使用这个原型。
回答by James
It's pretty common to have a company/product wide version of one of the following: -
拥有以下之一的公司/产品范围版本是很常见的:-
- A common parent pom with a dependency management section controlling all your versions
- A common pom which is included as a dependency and imports all the testing dependencies, e.g., my-company-test. That can either include your common test code as well or be of type
pom
and just act as a dependency vacuum. - An archetype (as frant.hartm says) which defines all of your common dependency versions up front.
- 一个常见的父 pom,带有控制所有版本的依赖项管理部分
- 一个常见的 pom,它作为依赖项被包含并导入所有测试依赖项,例如,my-company-test。这既可以包括您的通用测试代码,也可以是类型
pom
并且只是作为依赖真空。 - 一个原型(如 frant.hartm 所说),它预先定义了所有常见的依赖版本。
I would personally go with both the dependency based pom and an archetype which imports it.
我个人会同时使用基于依赖的 pom 和导入它的原型。
You can always override versions if you need too.
如果您也需要,您可以随时覆盖版本。
回答by Omoro
You have to state the version
that you want in the dependency, for example I use JUnit 4.11 in Eclipse Juno:
您必须version
在依赖项中声明您想要的,例如我在 Eclipse Juno 中使用 JUnit 4.11:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
So you need to set your version
to 4.10 or whatever version there is that you desire.
因此,您需要将您的version
版本设置为 4.10 或您想要的任何版本。