Access maven property using dependency management
Asked Answered
S

1

16

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.

Siftings answered 5/6, 2018 at 11:11 Comment(2)
put the dependencies outside of dependencyManagement. in dependencyManagement` you only define which lib is used if it is in an other modules is usedDna
@Jens: We need to import certain dependencies using dependency-management only as it is kind of BOMSiftings
A
10

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

Airworthy answered 5/6, 2018 at 11:38 Comment(2)
Thank David for suggestion! Actually I was already aware of properties-maven-plugin but don't want to read the properties file from outside as of now. Do you have any document or link where it is specified clearly that what all can be inherited when we import POM using dependency-management.Siftings
Thanks David! Actually, I got confused with the documentation as they haven't mentioned clearly that what can not be inherited..Siftings

© 2022 - 2024 — McMap. All rights reserved.