Maven: access version of transitive dependency via

2019-02-14 06:22发布

问题:

In a Maven project, one of my direct dependency has an indirect dependency com.foo:bar. What I need, is a Maven property (e.g. ${bar-version}) with the version number of this artifact. I need this mechanism for the version numbers of several indirect dependencies.

I learned from that question that I can access the local path of the artifact's jar with ${maven.dependency.com.foo.bar.jar.path} within the antrun plugin. The workaround I am using now, is to parse its value (e.g. /path/to/repository/com/foo/bar/2.1.1/bar-2.1.1.jar) within an antrun execution and define a property there (configuration exportAntProperties is my friend). However, since there is no good string regex manipulation in ant per default, this is quite cumbersome.

Are there other properties like ${maven.dependency.com.foo.bar.jar.path} available? I tried ${maven.dependency.com.foo.bar.jar.version}, but it did not work. I would also like to understand the mechanism behind this property. Is it backed by Java Classes? Like project.organization.name is getProject().getOrganizarion().getName() in the corresponding Maven Classes...

Any help welcome!

Thanks, Johannes