I am using maven's dependency-management to import the POM into my project Y as below:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.abc</groupId>
<artifactId>X</artifactId>
<version>1.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
And my artifact X has following properties which I want to access in POM of project Y:
<properties>
<property1>value1</property1>
<property2>value2</property2>
</properties>
I am not able to access properties defined in X into Project Y. I understand that using above approach I can't make use of plugin-management but I was unable to find anything related to properties on web.
Also please note I can't use the artifact X as parent as we have project level parent already defined.
Could you please guide on the same.
In maven pom. xml , a property is accessed by using ${property_name} . You can define your custom properties in Maven.
Dependency management in Maven allows teams to manage dependencies for multi-module projects and applications. These can consist of hundreds or even thousands of modules. Using Maven can help teams define, create, and maintain reproducible builds.
Properties are the last required piece to understand POM basics. Maven properties are value placeholders, like properties in Ant. Their values are accessible anywhere within a POM by using the notation ${X}, where X is the property.
You can only inherit properties from another pom, if you declare that as a parent. Importing a pom with type import
only imports its dependencies, as described in the documentation. Since using the other pom as a parent is not possible in your case, let me suggest an alternative:
The codehaus Properties Maven Plugin can load maven properties from an external file. It can even use classpath:
URLs to load files from. So you might try to load those from another dependency (which should have an appropriate scope
since you probably do not want that dependency's JAR to hang around at runtime).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With