Does Maven have a way to get the dependency version as a property?

I am using the specification to import dependencies from another project into mine, and I need a way to reference the version of dependencies that is already declared in the specified specification. So far I have tried to list the dependency version as a property in the specification, but this approach failed because the properties are not imported using the specifications.

I saw where the Dependency Plugin plugin is : dependency: the properties do almost what I need, but instead of giving me the full path, the Artifact I need a version as a property. Is there anything that can give me a version of the allowed artifact as a property?

UPDATE - "Why not use the parent pom?"

I usually find myself working in application server environments where the provided dependencies are specified using specification artifacts (this seems to have become a fairly common standard way to distribute groups of related artifacts, i.e. widlfly ). Therefore, I want to consider this specification as the only source of truth. The idea of ​​doing something like altering a property of a dependency version that has already been defined in the specification seems wrong.

If I defined the properties of the parent pom, which reflected the application server environment, now I need to worry about preserving the properties of the parent pom and the specification properties - why do they even have the specification at this point?

Information is already available in the dependency tree, it's just a matter of exposure ...

+7
java maven maven-bom
source share
3 answers

Could not find any existing maven or plugin functions for this, so I forked the old dependencypath-maven-plugin module and changed it to use versions. Now I can go into the plugin as follows:

<build> . . <plugins> . . <plugin> <groupId>io.reformanda.semper</groupId> <artifactId>dependencyversion-maven-plugin</artifactId> <version>1.0.0</version> <executions> <execution> <id>set-all</id> <goals> <goal>set-version</goal> </goals> </execution> </executions> </plugin> </plugins> </build> 

And access the following properties:

group_identifier: artifact: type [: classifier] .version

those.

io.undertow: surf-core: jar.version = 1.3.15.Final

See README for more information on how to use the plugin. This is available @ Maven Central :

 <dependency> <groupId>io.reformanda.semper</groupId> <artifactId>dependencyversion-maven-plugin</artifactId> <version>1.0.0</version> </dependency> 

... plugins all the way down ...

+7
source share

The short answer is yes, you can.

More details, your root pom.xml:

 <properties> <slf4j.version>1.7.21</slf4j.version> </properties> ... <dependencyManagement> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> ... </dependencyManagement> 

In pom.xml modules:

 <dependencies> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> </dependency> ... </dependencies> 

You can also use the value of $ {slf4j.version} to filter resources or in plugin configurations.

Update

If you cannot use the properties of the parent POM, you can

  • returns all dependencies and their versions with dependency: list ; or
  • use dependency together: list + antrun: run the plugin; or
  • configure CI server scripts to do this for you (for example, this example ); or
  • write a custom plugin to handle version logic.
+3
source share

This maven plugin is located on Github ( https://github.com/semper-reformanda/dependencyversion-maven-plugin ), and it is necessary for anyone dealing with Dependency versions, for example, when using Webjars dependencies - you can enter numbers Webjar versions directly to your web resources.

I have been looking for such functionality for a long time, I hope that more people will stumble on it and that it will stand on the central part of Maven (I actually think that it should appear with Maven out of the box)

0
source share

All Articles