依赖类型dependency type在maven中的作用

来源:互联网 发布:java项目的工作流程 编辑:程序博客网 时间:2024/06/01 07:18
dependency为什么会有type为pom,默认的值是什么? 

dependency中type默认为jar即引入一个特定的jar包。那么为什么还会有type为pom呢?当我们需要引入很多jar包的时候会导致pom.xml过大,我们可以想到的一种解决方案是定义一个父项目,但是父项目只有一个,也有可能导致父项目的pom.xml文件过大。这个时候我们引进来一个type为pom,意味着我们可以将所有的jar包打包成一个pom,然后我们依赖了pom,即可以下载下来所有依赖的jar包


看看下面这段pom配置

1
2
3
4
5
6
7
...
<dependency>
    <groupId>xxx</groupId>
    <artifactId>yyy</artifactId>
    <type>ejb</type>
</dependency>
...

这个<type>很多maven相关的资料中都未曾提及,而上网搜了一下中文资源,这些文章都把compile、runtime、test等本属于scope的概念混淆为“依赖类型”<type>的概念。而且,关于这个<type>的解释也非常少。

我也是看了Maven 3 Cookbook之后从中找到些只言片语,反推出type的作用。

看书中原文(P134. How it works...):

Adding the type of apk to the dependency allows the Maven Android plugin to find the Android package of the application.

不难看出,<type>apk</type>告诉maven使用maven android plugin来进行处理<type>为apk的依赖。从而推想<type>ejb</type>就是告诉maven使用maven ejb plugin来处理。如果想知道ejb plugin如何处理这类dependency,那就去查查ejb plugin的详细说明吧,这个plugin的说明网上有很多。


原创粉丝点击