maven 依赖相关
maven pom 依赖
有些找到的maven依赖写的type是pom类型, 一时不知如何处理.
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-walkthroughs -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-walkthroughs</artifactId>
<version>1.17.0</version>
<type>pom</type>
</dependency>
搜索了一番, 有两个用法.
- 放置在
<dependencyManagement>里面, 并且额外添加<scope>import </scope>, 可以使得这个pom依赖里的<dependencyManagement>也被引用进来, 但是具体<dependencies>里的依赖就不会被引用了. 后面需要使用, 还是需要参考<dependencyManagement>的用法, 额外写<dependency>, 只是不用写版本号. - 只是放置在
<dependencies>中作为简单依赖使用, 那就得看pom文件里写了哪些依赖项, 只有这些项目会被引用.
所以两种用法, 其实都需要具体查看下pom文件里的内容, 看看到底要怎么使用, 引用<dependencyManagement>或是<dependencies>.
比如上面flink的依赖, pom的文档在maven仓库里可以看到https://repo1.maven.org/maven2/org/apache/flink/flink-walkthroughs/1.17.0/flink-walkthroughs-1.17.0.pom. 里面并没有dependencyManagement的内容, 只有普通的dependencies依赖, 还不如直接去引用里面具体的子模块https://repo1.maven.org/maven2/org/apache/flink/flink-walkthrough-common/1.17.0/flink-walkthrough-common-1.17.0.pom
<!-- https://mvnrepository.com/artifact/org.apache.flink/flink-walkthrough-common -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-walkthrough-common</artifactId>
<version>1.17.0</version>
</dependency>
What is the difference between "pom" type dependency with scope "import" and without "import"
关键是这句话: So basically the two different mechanisms are used for importing/including the two different types of dependencies (managed dependencies and normal dependencies).
You can only import managed dependencies. This means you can only import other POMs into the dependencyManagement section of your project's POM. i.e.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>other.pom.group.id</groupId>
<artifactId>other-pom-artifact-id</artifactId>
<version>SNAPSHOT</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
What then happens is that all the dependencies defined in the dependencyManagement section of the other-pom-artifact-id are included in your POM's dependencyManagement section. You can then reference these dependencies in the dependency section of your POM (and all of its child POMs) without having to include a version etc.
However if in your POM you simply define a normal dependency to other-pom-artifact-id then all dependencies from the dependency section of the other-pom-artifact-id are included transitively in your project - however the dependencies defined in the dependencyManagement section of the other-pom-artifact-id are not included at all.
So basically the two different mechanisms are used for importing/including the two different types of dependencies (managed dependencies and normal dependencies).