Reputation: 422
In our project, we use a dependency-management pom which is imported into another maven project's pom. The dependency management pom has some properties. Is there a way to access the properties from the dependency management pom?
Also, I looked at other options. Having the dependency-management pom as a parent pom, but the maven project's pom already has a parent pom declared so that is not an option.
Using properties-maven-plugin, but I am not sure how to access the property from another pom using this plugin.
Below is the structure am working with.
** dependency-management pom:
<project>
<packaging>pom</packaging>
<groupId>group1</groupId>
<artifactId>artifact1</artifactId>
<name>management-pom</name>
<version>0.1</version>
<properties>
<test.version>0.2</test.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>group2</groupId>
<artifactId>artifact2</artifactId>
<version>${test.version}</version>
</dependency>
<dependencies>
<dependencyManagement>
</project>
** pom where dependency-management pom is imported:
<project>
<packaging>war</packaging>
<groupId>group3</groupId>
<artifactId>artifact3</artifactId>
<name>war-pom</name>
<version>0.1</version>
<properties>
<!--how to access the dependency-management pom's properties here?-->
<maven.test.version>${test.version}</maven.test.version>
</properties>
<dependencies>
<dependency>
<groupId>group2</groupId>
<artifactId>artifact2</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>group1</groupId>
<artifactId>artifact1</artifactId>
<version>0.1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependencies>
<dependencyManagement>
</project>
The closest question I found was Access maven property using dependency management which was asked 4 years ago and it did not have an answer that I was looking for.
Any help is much appreciated.
Upvotes: 0
Views: 87
Reputation: 422
I did find this plugin https://gitlab.com/josh-cain/dependencyversion-maven-plugin.
This did the job of getting the dependency version from the pom that was getting imported.
So using this plugin, now I am able to directly access the version of the dependency which was getting exported as a property using this plugin.
Used the below snippet in the code.
${group2:artifact2.jar.version}
Upvotes: 0