0

我有一个关于 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>

我无法理解 <classifier> 和 <type> 的用法。

我的问题是:

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

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

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

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

[错误] 未能在项目测试中执行目标:无法解析项目 com.ruan:test:jar:1.0-SNAPSHOT 的依赖项:未能找到 org.opendaylight.controller:features-restconf:xml:1.2.1-Lithium- http://nexus.opendaylight.org/content/repositories/public/中的SR1 被缓存在本地存储库中,直到 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
4

1 回答 1

0

正如您的 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 构建但内容不同的工件。它是一些可选且任意的字符串——如果存在的话——被附加到工件名称之后,紧跟在版本号之后。

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

于 2015-10-29T07:39:43.230 回答