一,父子模块引用jar版本管理
dependencyManagement是父类pom管理所有引入jar包的版本信息,子模块要使用该jar包时,需要显示使用dependencies,不写version,如果需要不同的版本时,显示指定version。
这样做的目的是,统一版本号,个性化时指定版本号。
实际使用时,发现并不好用,不推荐使用。
达到上面的同样的目的,直接在父模块pom中使用dependencies,指定版本号。子模块不用再写dependencies,即可达到使用父模块的引用,如果需要指定版本时,才自定义dependencies即可。
比上面的方式便捷
宁外发现一个dependencyManagement一个作用,网上没找到相关解释。
我平行的子模块之间的依赖时,按常理,我只要使用dependencies 定义即可。但是,maven编译打包始终报错。
如上图,我doubleColor要依赖同是子模块的common模块,当我在doubleColor的pom中写:
<dependencies>
<dependency>
<artifactId>com.hk.test</artifactId>
<groupId>common</groupId>
<version>${parent.version}</version>
</dependency>
</dependencies>
出现maven报错:
common模块的pom是这样写的:
<parent>
<artifactId>com.hk.test</artifactId>
<groupId>testDel</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>common</artifactId>
当我把doubleColor的pom改为dependencyManagement时,报错解除了
<dependencyManagement>
<dependencies>
<dependency>
<artifactId>com.hk.test</artifactId>
<groupId>common</groupId>
</dependency>
</dependencies>
</dependencyManagement>
什么情况,有懂的给我解释下。
-------修改
dependencyManagement 还是不能真正的引用,上面我的dependencies 写错了,正确的引用:
<dependencies>
<dependency>
<groupId>testDel</groupId>
<artifactId>common</artifactId>
<version>${parent.version}</version>
</dependency>
</dependencies>