原帖地址:http://uule.iteye.com/blog/2087485
Dependency scope 是用来限制Dependency的作用范围的, 影响maven项目在各个生命周期时导入的package的状态。
自从2.0.9后,新增了1种,现在有了6种scope:
-
compile
默认的scope,表示 dependency 都可以在生命周期中使用。而且,这些dependencies 会传递到依赖的项目中。 -
provided
跟compile相似,但是表明了dependency 由JDK或者容器提供,例如Servlet AP和一些Java EE APIs。这个scope 只能作用在编译和测试时,同时没有传递性。 - 使用这个时,不会将包打入本项目中,只是依赖过来。
- 使用默认或其他时,会将依赖的项目打成jar包,放入本项目的Lib里
- 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.
-
- <!-- Servlet -->
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>2.5</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet.jsp</groupId>
- <artifactId>jsp-api</artifactId>
- <version>2.1</version>
- <scope>provided</scope>
- </dependency>
-
runtime
表示dependency不作用在编译时,但会作用在运行和测试时 -
test
表示dependency作用在测试时,不作用在运行时。 -
system
跟provided 相似,但是在系统中要以外部JAR包的形式提供,maven不会在repository查找它。 例如:
<project>
...
<dependencies>
<dependency>
<groupId>javax.sql</groupId>
<artifactId>jdbc-stdext</artifactId>
<version>2.0</version>
<scope>system</scope>
<systemPath>${java.home}/lib/rt.jar</systemPath>
</dependency>
</dependencies>
...
</project>
-
import (Maven 2.0.9 之后新增)
它只使用在<dependencyManagement>中,表示从其它的pom中导入dependency的配置,例如: This scope is only used on a dependency of type pom in the <dependencyManagement> section. It indicates that the specified POM should be replaced with the dependencies in that POM's <dependencyManagement> section. Since they are replaced, dependencies with a scope of import do not actually participate in limiting the transitivity of a dependency.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>B</artifactId>
<packaging>pom</packaging>
<name>B</name>
<version>1.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>maven</groupId>
<artifactId>A</artifactId>
<version>1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>test</groupId>
<artifactId>d</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
B项目导入A项目中的包配置
相关推荐
在其他项目中直接依赖使用,比如:公用的方法,权限组件等等。 一,新建一个简单的Maven工程,这个Maven工程只含一个pom文件,他是管理各个模块的父级POM,如: Xml代码 <packaging>pom</packaging> <modules> ...
单元测试 该项目有助于向项目添加单元测试依赖项 - JUnit、Hamcrest、Mockito 和 PowerMock。 项目的 POM 确保您不会有可能导致类加载问题的重复依赖项(例如 hamcrest-core ... < scope>test</ scope> </ dependency>
在Maven项目中,您将在<dependencyManagement />POM 的部分中声明此依赖项,如下所示: 示例1.使用Spring Data版本系列BOM <dependencyManagement> <dependency> <groupId>org.springframework.data ...
好消息,mongodb 现在提供了一个 rx 驱动: : 这个项目现在已经死了,请使用 mongo-java-driver-rx mongo-driver-async-rxadapter 用于 Mongo 3 异步驱动程序的 RxJava 适配器 用法 new RxMongoClient(mongoClient...
Stackify Logback记录器 Logback记录器追加程序,用于将日志消息和异常发送到Stackify。 错误和日志概述: : ...安装 ... < scope>runtime</ scope> </ dependency> 用法 附加程序配置示例: < a
Stackify Log4j2记录器 Log4j 2.x附加程序,用于将日志消息和异常发送到Stackify。 错误和日志概述: : ... < scope>runtime</ scope> </ dependency> 用法 配置示例: < StackifyLog name =
用法 将依赖项添加到您的 Maven POM: < dependency> < groupId>com.bytebybyte.gwt</ groupId> < artifactId>jquery-lib < version>2.1.3 < scope>provided</ scope> </ dependency> < dependency> ...
用法 将依赖项添加到您的 Maven POM: < dependency> < groupId>com.bytebybyte.gwt</ groupId> < artifactId>jquery-lib < version>2.1.3 < scope>provided</ scope> </ dependency> < dependency> ...
下图是性能的比较测试结果:使用方法:HikariConfig config = new HikariConfig(); config.setMaximumPoolSize(100); config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); ...
安装将其添加为Maven依赖项: < dependency> < groupId>com.stackify</ groupId> < artifactId>stackify-log-log4j12</ artifactId> < version>4.0.1</ version> < scope>runtime</ scope></ dependency>...
<dependency><groupId>com.github.neothemachine</groupId><artifactId>gwt-webdriver-junit-runstyle</artifactId><version>0.0.1-SNAPSHOT</version><scope>test</scope></dependency>调整gwt-maven-plugin使用的...
使用IPOG(按参数顺序通用)生成t路测试用例。 玛文 抖动位于Maven中央存储库中。 < dependency> < groupId>com.github.jesg</ groupId> < artifactId>dither < version>0.2.0 < scope>test</ scope> </ ...
使用方法如下,maven直接引入即可。 <dependency> <groupId>myjar <artifactId>aspose-words-21.11-jdk17 <scope>system</scope> <version>1.8.0 ${project.basedir}/src/lib/aspose-words-21.11-jdk17-1.0.jar...
用法 在您的dependencyManagement部分中包含此物料清单,以获取正确匹配版本的所有框架库,而无需在dependencies声明中明确提及它们。 Maven: < dependency> < groupId>io.holixon.axon < artifactId>axon-...
<scope>test</scope> <version>1.3 </dependency> 没有依赖 匹配的演示文稿 第一次比赛 String s = "a string"; Matcher<String> m = is(equalTo(s)); 这个对象m有一个方法match(Object item):boolean ...
这个包装器使用 Maven。 你可以得到 maven。 在您的项目中使用以下依赖项: <dependency> <groupId>com.checkmate.sdk</groupId> <artifactId>checkmate-java-sdk <version>1.0.0 <scope>compile</scope> </...
java笔试题算法福尔瑟姆 Folsom 是一个小而稳定的内存缓存客户端的尝试。 Folsom 是完全异步的,基于 ...<scope>import</scope> </dependency> <!-- In dependencies section --> <dependency> <gro
使用方法 ♡maven的相关依赖,注意范围只需要写test就可以了 < dependency> < groupId>com.github.davidfantasy</ groupId> < artifactId>mybatis-plus-generator-ui < version>1.4.2 < scope>test</ scope> ...
<scope>compile</scope> </dependency> 如果你想自己编译它,方法如下: $ git clone git@github.com:bandwidthcom/java-bandwidth-iris.git $ cd java-bandwidth-iris $ mvn install 用法 创建客户端 IrisClient ...
Selenium视觉差异 目标 目标是更好地集成 maven 执行的selenium2功能测试中的屏幕截图、屏幕截图的存储和版本控制,以获得两个应用程序版本之间的视觉差异报告。... <scope>test</scope> </dependency