how to access properties defined in other module pom in maven multimodule project
Asked Answered
P

2

11

In pom of A.B.C i have defined a property as abc where A B C are modules. Now i want to access that property in pom of A.D.F module.

<properties>
<A.B.C>${buildNumber}</A.B.C>
</properties>

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                <id>buildnumber</id>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
            <timestampFormat>{0,date,dd-MM-yyyy HH:mm:ss}</timestampFormat>
            <doCheck>false</doCheck>
            <doUpdate>false</doUpdate>
            <providerImplementations>
                <svn>javasvn</svn>
            </providerImplementations>
            <revisiononscmfailure>

                    <!-- 71 Generate sequence build number based on: 72 build number and 
                        timestamp 73 -->

                    <format>Build: #{0} ({1,date})</format>

                    <items>

                        <item>buildNumber\d*</item>

                        <item>timestamp</item>

                    </items>

                </revisiononscmfailure>
        </configuration>
        <dependencies>
            <dependency>
                <groupId>com.google.code.maven-scm-provider-svnjava</groupId>
                <artifactId>maven-scm-provider-svnjava</artifactId>
                <version>2.1.1</version>
            </dependency>
            <dependency>
                <groupId>org.tmatesoft.svnkit</groupId>
                <artifactId>svnkit</artifactId>
                <version>1.8.5</version>
            </dependency>
        </dependencies>

        </plugin>

I am using ${A.B.C} as value of version in a dependency in A.D.F module's pom.

<dependency>
        <groupId></groupId>
        <artifactId></artifactId>
        <version>${A.B.C}</version>
        <type>bundle</type>
    </dependency>

So it is giving me error: bundle must be a valid version but is ${A.B.C}.

EDIT:

or can i use version of C module in someway as i have defined:

<version>${A.B.C}</version> 
Pollination answered 26/8, 2014 at 6:42 Comment(2)
Which maven version do you use?Stink
I would recommend to upgrade to Maven 3.2.1 than you can use ` ${revision}, ${changelist}, and ${sha1}` in versions.Stink
P
2

Explanation provided in answer of this question explains it in a very good manner that what can be used and when.

Reading Properties file from POM file in Maven

Pollination answered 28/8, 2014 at 6:21 Comment(1)
I marked this up because the link was very useful. However, I hesitated because you failed to add a summary of what the link says about the question here.Arcane
D
3

Do those modules share a parent pom? Seems like if you want them linked, it would be a good idea to have them share properties via parent, especially if you want to tightly couple module versions between many modules.

Dingdong answered 26/8, 2014 at 6:49 Comment(6)
A is parent of all modules. But how will i define property <A.B.C>${buildNumber}</A.B.C> in parent POM as buildnumber is provided by buildnumber-maven-pluginPollination
So if I understand correctly, the buildnumber plugin defines the version at build time. Therefore, the child pom cannot properly inherit the version number? If this is the case, what if you were to write the buildnumber out to a properties file, and have the child pom use the properties file plugin to read the buildnumber from the file generated by building child module C? I am under the assumption you will build C before building F. It sounds kind of hacky, I know :)Dingdong
i liked ur solution but dont know how to do thatPollination
How to access same properties file across multi module project which has nested modulesPollination
Have you tried reading in the file from the parent and just inheriting the property in all children? (use parent tag in child poms) Apologies if I can't provide more detail. I'm just kind of putting together different solutions I've done in the past, but never all done at once.Dingdong
While I agree with this poster, it is not always possible. Sometimes the constraints of the job make this impossible.Arcane
P
2

Explanation provided in answer of this question explains it in a very good manner that what can be used and when.

Reading Properties file from POM file in Maven

Pollination answered 28/8, 2014 at 6:21 Comment(1)
I marked this up because the link was very useful. However, I hesitated because you failed to add a summary of what the link says about the question here.Arcane

© 2022 - 2024 — McMap. All rights reserved.