什么是< scope>在< dependency>下在pom.xml中进行? [英] What is <scope> under <dependency> in pom.xml for?

查看:83
本文介绍了什么是< scope>在< dependency>下在pom.xml中进行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看文档 http://maven.apache.org/surefire/maven- surefire-plugin/examples/testng.html ,我们可以在<dependency>

Looking at documentation http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html, we can see <scope> tag under <dependency>

那是什么,我们如何使用它进行测试?

What is that and how can we use it for running test?

推荐答案

<scope>元素可以采用6个值: compile 提供 runtime 测试系统导入.

The <scope> element can take 6 values: compile, provided, runtime, test, system and import.

此作用域用于限制依赖项的可传递性,并影响用于各种构建任务的类路径.

This scope is used to limit the transitivity of a dependency, and also to affect the classpath used for various build tasks.

编译

这是默认范围,如果未指定则使用.编译依赖项在项目的所有类路径中均可用.此外,这些依赖关系会传播到依赖项目中.

This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

提供

这很像编译,但是表明您希望JDK或容器在运行时提供依赖项.例如,在为Java Enterprise Edition构建Web应用程序时,您将对Servlet API和相关Java EE API的依赖关系设置为所提供的范围,因为Web容器提供了这些类.此作用域仅在编译和测试类路径上可用,并且不可传递.

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

运行时

此作用域表示依赖关系不是编译所必需的,而是执行所必需的.它在运行时和测试类路径中,而不在编译类路径中.

This scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

测试

此范围表明依赖关系对于正常使用应用程序不是必需的,并且仅在测试编译和执行阶段可用.

This scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases.

系统

此作用域与提供的作用域相似,不同之处在于您必须提供显式包含它的JAR.该工件始终可用,并且不会在存储库中查找.

This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.

导入(仅在Maven 2.0.9或更高版本中可用)

import (only available in Maven 2.0.9 or later)

此作用域仅在本节中用于pom类型的依赖项上.它指示应使用该POM部分中的依赖项替换指定的POM.由于已将它们替换,因此具有导入范围的依赖项实际上并不参与限制依赖项的可传递性.

This scope is only used on a dependency of type pom in the section. It indicates that the specified POM should be replaced with the dependencies in that POM's section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.

要回答问题的第二部分:

To answer the second part of your question:

我们如何使用它进行测试?

How can we use it for running test?

请注意,test范围仅允许在测试阶段使用依赖项.

Note that the test scope allows to use dependencies only for the test phase.

有关详细信息,请阅读文档

Read the documentation for full details.

这篇关于什么是&lt; scope&gt;在&lt; dependency&gt;下在pom.xml中进行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆