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项目中的包配置
相关推荐
NULL 博文链接:https://dannyhz.iteye.com/blog/2249427
在POM 4中,<dependency>中还引入了<scope>,它主要管理依赖的部署。目前<scope>可以使用5个值: • compile,缺省值,适用于所有阶段,会随着项目一起发布。 • provided,类似compile,期望JDK、容器或使用者会...
Maven项目管理工具,可以将一个完整的项目拆成一个一个模块进行开发,而一些比较通用的模块就可以作为公用组件。在其他项目中直接依赖使用,比如:公用的方法,权限组件等等。 一,新建一个简单的Maven工程,这个...
本教程是基于MyEclipse环境下基于maven搭建的springmvc步骤(图文教程),文章结尾含有源码下载地址: 新建maven project File->New->Project 选择Maven Project 选择项目路径 Use default Workspace location默认...
Maven依赖管理 (Dependency Management) 3.5.6. 站点生成和报告 (Site Generation and Reporting) 3.6. 小结 4. 定制一个Maven项目 4.1. 介绍 4.1.1. 下载本章样例 4.2. 定义Simple Weather项目 4.2.1...
6. 新增Dependency Scope 这点也比较重要,有些用于test范围的包,可以不用加入依赖了 7. 传递依赖,简化依赖管理 这是最为方便的,可以省了很多配置。如a 依赖 b,b 依赖c 默认 a也会依赖 c。但是也会带来隐患,...
<scope>test</scope> </dependency> <dependency> <groupId>javax.servlet <artifactId>javax.servlet-api <version>3.1.0 </dependency> <!-- mybatis依赖的jar包 --> <dependency> <groupId>org....
Dependency management - including transitive dependencies, scope recognition and SNAPSHOT handling Artifact deployment - deployment to a Maven repository (file integrated, other with extensions) POM ...
<scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot <artifactId>spring-boot-starter-web </dependency> <dependency> <groupId>org.springframework.boot <artifactId>...
* [MNG-4953] - Issue a warning when a system-scope dependency refers to the project basedir ** New Feature * [MNG-4936] - Allow to better monitor and adjust a Maven build during CI * [MNG-4937] - ...
Dependency management - including transitive dependencies, scope recognition and SNAPSHOT handling Artifact deployment - deployment to a Maven repository (file integrated, other with extensions) POM ...
跑批项目打了jar包后,运行一直找不到主类或者找不到classpath下的依赖。 解决方法: ... <scope>runtime</scope> </dependencySet> <directory>src/main/bin <outputDirectory>/ </assembly>
maven 导入 <dependency> <groupId>com.kingbase8.jdbc</groupId> <artifactId>kingbase8 <version>8.6.0 <scope>system</scope> ${basedir}/src/main/resources/jar/kingbase8-8.6.0.jar </dependency> jdbc ...
ssm在maven项目管理下的pom文件,jar包依赖 <dependency> <groupId>javax.servlet <artifactId>javax.servlet-api <version>3.1.0 <scope>provided</scope> </dependency> <dependency> <groupId>javax....
<scope>system</scope> ${JAVA_HOME}/lib/tools.jar </dependency> <dependency> <groupId>junit <artifactId>junit <version>3.8.1 <scope>test</scope> </dependency> </project>
<scope>provided</scope> </dependency> <!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 --> <directory>src/main/java **/*.properties **/*.xml <filtering>false ...
<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency>数据库: MYSQL(5.xx) ; NoSQL : Redis (并非用的很多);其他工具推荐谷歌...
<scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot <artifactId>spring-boot-starter-web </dependency> <dependency> <groupId>mysql ...
除了项目构建,Maven最核心的功能是软件包的依赖管理,能够自动分析项目所需要的依赖软件包,并到Maven中心仓库去下载。 A)管理依赖的jar包 B)管理工程之间的依赖关系。 3.2. Maven本地仓库 在当前系统用户的...
J2V8 是 V8 引擎的 Java ...Maven:<dependency> <groupId>com.eclipsesource.j2v8</groupId> <artifactId>j2v8_win32_x86_64 <version>2.2.1 <scope>compile</scope> </dependency> 标签:J2V8