0

I hava a question about Maven pom.xml.

I add a dependency in pom.xml like:

<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>

I can not understand the usage of < classifier > and < type >.

My questions are:

  1. What is the meaning of classifier and type
  2. What is the meaning of scope(runtime) while the type is xml. I guess xml means maven needs a xml file, but what is it to do with runtime? I think runtime is always associated with "added to classpath", but why xml?

If I comment on < type > I got error like:

[ERROR] Failed to execute goal on project test: Could not resolve dependencies for project com.ruan:test:jar:1.0-SNAPSHOT: Failure to find org.opendaylight.controller:features-restconf:jar:features:1.2.1-Lithium-SR1 in http://nexus.opendaylight.org/content/repositories/public/ was cached in the local repository, resolution will not be reattempted until the update interval of opendaylight-mirror has elapsed or updates are forced -> [Help 1]

If I comment on < classifier > I got error like:

[ERROR] Failed to execute goal on project test: Could not resolve dependencies for project com.ruan:test:jar:1.0-SNAPSHOT: Failure to find org.opendaylight.controller:features-restconf:xml:1.2.1-Lithium-SR1 in http://nexus.opendaylight.org/content/repositories/public/ was cached in the local repository, resolution will not be reattempted until the update interval of opendaylight-mirror has elapsed or updates are forced -> [Help 1]

If I run it correctly, I got the directory like:

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
ruanhao
  • 4,663
  • 6
  • 28
  • 43

1 Answers1

0

As your artifactId indicates, you are including a dependency with the features-restconf of opendaylight controller.

If you check the code of the controller in github repostory:

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

you will notice that there is a directory named "features" which contains a pom.xml file. If you open that pom.xml file, you can see that it corresponds with artifactId features-controller, and that have differente modules:

<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>

And that for every of those modules, there is a subfolder created inside features directory. For every subfolder, there is a features.xml in the next path: /src/main/resources/features.xml

So with the dependency that you have sent, what you are telling to pom is that it is necessary to attach all the other dependencies indicated in those features.xml files, and that every of those dependencies are not necessary in compilation time, but they will be necessary in execution time (runtime).

For more info about what is the meaning of every pom.xml tag:

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

There, you will read:

classifier: The classifier allows to distinguish artifacts that were built from the same POM but differ in their content. It is some optional and arbitrary string that - if present - is appended to the artifact name just after the version number.

scope: This element refers to the classpath of the task at hand (compiling and runtime, testing, etc.) as well as how to limit the transitivity of a dependency. runtime --> this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath.

J. Reyes
  • 41
  • 1
  • 6