类型= pom的Maven依赖 [英] Maven dependency with type = pom

查看:93
本文介绍了类型= pom的Maven依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在父POM中声明

<dependencyManagement>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons-lang3.version}</version>
            <scope>compile</scope>
        </dependency>
</dependencyManagement>

进一步,孩子使用pom

Further, the child pom use

<dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
</dependencies>

一切正常吗?但是当我将这种依赖关系与type = pom

All work fine? but when I use such dependency with type = pom

<dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.jboss.spec</groupId>
                <artifactId>jboss-javaee-7.0</artifactId>
                <version>${jboss-javaee-7.0.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
</dependencyManagement>

我有错

[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project by.services:by.utils:1.0.2 (D:\Work\V2_Change_Maven_Structure\by.utils\pom.xml) has 1 error
[ERROR]     'dependencies.dependency.version' for org.jboss.spec:jboss-javaee-7.0:jar is missing. @ line 18, column 21
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

如何在dependencyManagement中声明类型为pom的依赖项$ {Jboss-javaee-7.0.version}宣布如果我在根目录中包含jboss-javaee-7.0,则运行

How to declare a dependency in dependencyManagement with type = pom $ {Jboss-javaee-7.0.version} announced If I bear jboss-javaee-7.0 in the root, then runs

推荐答案

此处的说明是,当您未在</dependency>上定义< type> </dependencyManagement> 中的code>,它会分配给 jar

The clarification here is that when you do not define <type> on your </dependency> within </dependencyManagement> it defults to jar

<dependencyManagement>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>${commons-lang3.version}</version>
        <scope>compile</scope>
        <type>jar<type> <!--default value-->
    </dependency>
</dependencyManagement>

,因此 module 在使用该jar的同时将其用作

and hence the module uses that jar while using it as

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-lang3</artifactId>
</dependency> 

依赖项的类型.默认为 jar .虽然通常表示依赖项文件名的扩展名,并非总是如此.可以将类型映射到其他扩展名和分类器.类型通常与所使用的包装相对应,尽管并非总是如此.一些示例是 jar war ejb-client test-jar 可以通过将扩展名设置为 true 的插件来定义新类型,因此这不是完整的列表.

The type of dependency. This defaults to jar. While it usually represents the extension on the filename of the dependency, that is not always the case. A type can be mapped to a different extension and a classifier. The type often corresponds to the packaging used, though this is also not always the case. Some examples are jar, war, ejb-client and test-jar New types can be defined by plugins that set extensions to true, so this is not a complete list.


但是接下来,当您显式声明父pom具有类型为


But next when you explicitly declare the parent pom to have the type as

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.jboss.spec</groupId>
            <artifactId>jboss-javaee-7.0</artifactId>
            <version>${jboss-javaee-7.0.version}</version>
            <type>pom</type><!--override the default value-->
            <scope>import</scope>
        </dependency>
</dependencyManagement>

子模块现在可以继承与

<dependency>
     <groupId>org.jboss.spec</groupId>
     <artifactId>jboss-javaee-7.0</artifactId>
     <type>pom</type><!--inherited-->
</dependency>

或者,如果您想利用与另一个< type> 不同的项目的jar,则可以将依赖项明确提到为:

OR if you want to utilize the jar of the project which is a different <type>, you can explicitly mention the dependency as :

<dependency>
     <groupId>org.jboss.spec</groupId>
     <artifactId>jboss-javaee-7.0</artifactId>
     <version>${jboss-javaee-7.0.version}</version>
     <type>jar</type> <!--different from parent-->
</dependency>

这篇关于类型= pom的Maven依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆