深圳网站建设公司哪家最好,网站建设属于什么经济科目,公司有必要建设网站吗,永康物流网站目录1. 依赖传递2. 什么是依赖冲突3. 怎么解决4. 项目聚合maven是一个项目管理的工具#xff0c;从项目的构建到项目开发#xff0c;再到项目的测试#xff0c;项目上线#xff0c;都可一键管理。1. 那么#xff0c;还有maven是如何管理项目中所用到的jar版本冲突#xf…
目录1. 依赖传递2. 什么是依赖冲突3. 怎么解决4. 项目聚合maven是一个项目管理的工具从项目的构建到项目开发再到项目的测试项目上线都可一键管理。1. 那么还有maven是如何管理项目中所用到的jar版本冲突在传递依赖时怎么解决
2. 如何创建父子依赖的项目1. 依赖传递
在maven中依赖是可以传递的假设存在三个项目分别是项目A项目B以及项目C。
假设C依赖BB依赖A那么我们可以根据maven项目依赖的特征不难推出项目C也依赖A。2. 什么是依赖冲突
由于依赖传递现象的存在特定情况下会造成依赖冲突。 spring-context 依赖了spring-beans
3. 怎么解决
1. 使用maven提供的依赖调解原则 第一声明者优先原则在 pom 文件中定义依赖以先声明的依赖为准。其实就是根据坐标导入的顺序来确定最终使用哪个传递过来的依赖路径近者优先原则在 pom 文件定义依赖以路径近者为准。2. 排除依赖使用exclusions标签将传递过来的依赖排除出去dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scopeexclusionsexclusiongroupIdorg.junit.vintage/groupIdartifactIdjunit-vintage-engine/artifactId/exclusion/exclusions/dependency3. 锁定版本采用直接锁定版本的方法确定依赖jar包的版本版本锁定后则不考虑依赖的声明顺序或依赖的路径以锁定的版本为准添加到工程中此方法在企业开发中经常使用版本锁定的使用方式:第一步在dependencyManagement标签中锁定依赖的版本第二步在dependencies标签中声明需要导入的maven坐标pom文件中使用dependencyManagement标签进行依赖jar的版本锁定并不会真正将jar包导入到项目中只是对这些jar的版本进行锁定。项目中使用哪些jar包还需要在dependencies标签中进行声明dependencies标签需要导入依赖时只需要指定groupId和artifactId无须再指定version即创建父子项目springboot就是典型的父子依赖的项目。
4. 项目聚合
项目聚合父项目子项目1子项目2...父项目锁定版本
?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersion!-- 父项目版本信息 --groupIdcn.bitqian/groupIdartifactIdparent/artifactIdversion0.0.1-SNAPSHOT/versionpackagingpom/packagingnameparent/nameurlhttp://maven.apache.org/urlpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncoding!-- spring版本抽取 --spring-version5.0.10.RELEASE/spring-versionmybatis-version2.1.3/mybatis-version/properties!-- 父项目的依赖管理 --dependencyManagementdependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion${spring-version}/version/dependencydependencygroupIdorg.mybatis.spring.boot/groupIdartifactIdmybatis-spring-boot-starter/artifactIdversion${mybatis-version}/version/dependency/dependencies/dependencyManagement!--子项目这两个小模块在下面创建完了才有的。 --modulesmodulechild01/modulemodulechild02/module/modules
/project有一个坑父项目打包的方式必须是pom, 而且eclipse创建完成后会包莫名其妙的错误… 解决如下。
child01,骨架是quick start
?xml version1.0?
project xsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancemodelVersion4.0.0/modelVersion!-- 父项目 --parentgroupIdcn.bitqian/groupIdartifactIdparent/artifactIdversion0.0.1-SNAPSHOT/version/parent!-- 当前项目 的版本信息 --groupIdcn.bitqian.child01/groupIdartifactIdchild01/artifactIdversion0.0.0.1-SNAPSHOT/versionnamechild01/nameurlhttp://maven.apache.org/urlpropertiesproject.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependencies!-- 无需写版本号因为依赖传递引用了父项目中的依赖 --dependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactId/dependency dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion3.8.1/versionscopetest/scope/dependency/dependencies
/project
child02 就不演示了根模块01一样只不过是选的webapp作为骨架。