【问题标题】:Usage of Maven pom tagMaven pom标签的使用
【发布时间】:2016-01-29 03:59:40
【问题描述】:

我有一个关于 Maven pom.xml 的问题。

我在 pom.xml 中添加了一个 依赖,例如:

<dependencies>
    <dependency>
            <groupId>org.opendaylight.controller</groupId>
            <artifactId>features-restconf</artifactId>
            <version>1.2.1-Lithium-SR1</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>runtime</scope>
    </dependency>
</dependencies>

的用法我看不懂。

我的问题是:

  1. classifiertype是什么意思
  2. 范围(运行时)是什么意思,而类型是xml。我猜 xml 意味着 maven 需要一个 xml 文件,但它与它有什么关系 运行时?我认为 runtime 总是与“添加到类路径”相关联,但为什么是 xml?

如果我对 发表评论,我会收到如下错误:

[ERROR] 未能在项目测试中执行目标:无法解决 项目 com.ruan:test:jar:1.0-SNAPSHOT 的依赖项:失败 找 org.opendaylight.controller:features-restconf:jar:features:1.2.1-Lithium-SR1 在http://nexus.opendaylight.org/content/repositories/public/ 是 缓存在本地仓库中,不会重新尝试解析 直到 opendaylight-mirror 的更新间隔已过或 强制更新 -> [帮助 1]

如果我对 发表评论,我会收到如下错误:

[ERROR] 未能在项目测试中执行目标:无法解决 项目 com.ruan:test:jar:1.0-SNAPSHOT 的依赖项:失败 找 org.opendaylight.controller:features-restconf:xml:1.2.1-Lithium-SR1 在 http://nexus.opendaylight.org/content/repositories/public/ 已缓存 在本地存储库中,将不会重新尝试解析,直到 opendaylight-mirror 的更新间隔已过或更新是 强制 -> [帮助 1]

如果我运行正确,我会得到如下目录:

haoruan:~/.m2/repository/org/opendaylight/controller/features-restconf $ cd 1.2.1-Lithium-SR1/
total 96
-rw-r--r--  1 haoruan  staff   264B Oct 29 13:58 _remote.repositories
-rw-r--r--  1 haoruan  staff   397B Oct 29 13:38 features-restconf-1.2.1-Lithium-SR1-features.jar.lastUpdated
-rw-r--r--  1 haoruan  staff   9.0K Oct 29 13:58 features-restconf-1.2.1-Lithium-SR1-features.xml
-rw-r--r--  1 haoruan  staff    40B Oct 29 13:58 features-restconf-1.2.1-Lithium-SR1-features.xml.sha1
-rw-r--r--  1 haoruan  staff    12K Oct 29 13:38 features-restconf-1.2.1-Lithium-SR1.pom
-rw-r--r--  1 haoruan  staff    40B Oct 29 13:38 features-restconf-1.2.1-Lithium-SR1.pom.sha1
-rw-r--r--  1 haoruan  staff   397B Oct 29 13:39 features-restconf-1.2.1-Lithium-SR1.xml.lastUpdated

【问题讨论】:

    标签: java maven-3 opendaylight


    【解决方案1】:

    正如您的 artifactId 所指示的,您正在包含与 opendaylight 控制器的 features-restconf 的依赖关系。

    如果您在 github 存储库中检查控制器的代码:

    https://github.com/opendaylight/controller/releases/tag/release%2Flithium-sr1
    

    您会注意到有一个名为“features”的目录,其中包含一个 pom.xml 文件。如果你打开那个 pom.xml 文件,你可以看到它对应于 artifactId features-controller,并且有不同的模块:

    <module>config</module>
    <module>config-persister</module>
    <module>config-netty</module>
    <module>mdsal</module>
    <module>netconf</module>
    <module>protocol-framework</module>
    <module>akka</module>
    <module>netconf-connector</module>
    <module>restconf</module>
    <module>extras</module>
    

    对于每个模块,在 features 目录中都创建了一个子文件夹。对于每个子文件夹,在下一个路径中都有一个 features.xml:/src/main/resources/features.xml

    因此,对于您发送的依赖项,您要告诉 pom 有必要附加这些 features.xml 文件中指示的所有其他依赖项,并且在编译时不需要每个依赖项,但它们在执行时(运行时)是必需的。

    有关每个 pom.xml 标签的含义的更多信息:

    https://maven.apache.org/pom.html
    

    在那里,你会读到:

    分类器: 分类器允许区分从相同 POM 构建但内容不同的工件。它是一些可选且任意的字符串 - 如果存在 - 会在版本号之后附加到工件名称。

    范围: 该元素指的是手头任务的类路径(编译和运行时、测试等)以及如何限制依赖项的传递性。 runtime --> 这个范围表示依赖不是编译所必需的,而是执行所必需的。它在运行时和测试类路径中,但不在编译类路径中。

    【讨论】:

      猜你喜欢
      • 2011-12-23
      • 2019-08-18
      • 2021-02-21
      • 2018-05-16
      • 1970-01-01
      • 1970-01-01
      • 2011-05-12
      • 2011-05-30
      • 2017-04-10
      相关资源
      最近更新 更多