4

We have a couple of different applications which may or may not interact together. When they interact together, there have been issues because of mismatch in third party library versions (Let it be Spring or something else).

The pom files for these applications are separate, but to solve the above issue, we want them to use the same versions of third party libraries. The easiest way to do this is to specify the versions in common properties file, and then let respective pom.xml read the versions from the properties file.

Usually I am used to specify the versions as properties in the parent pom, and let the module pom read it from there. Is there a way I can make pom.xml read the properties file for reading the versions?

illcar
  • 439
  • 1
  • 5
  • 13
  • 1
    possible duplicate of [Maven - Reading a property from an external properties file](http://stackoverflow.com/questions/9912632/maven-reading-a-property-from-an-external-properties-file) – jmj Sep 10 '14 at 22:57
  • @JigarJoshi, looking at the link that you specified, I guess it's not possible to accomplish this then. – illcar Sep 10 '14 at 23:02
  • You should start using dependencyManagement in your (company-) parent which is exactly intended for such purposes. – khmarbaise Sep 11 '14 at 06:42

1 Answers1

0

Some projects, e.g. spring-cloud and spring-boot, express their 'release train' (a set of dependencies and their versions that are known to work well together) in a 'BOM' (bill of materials). The BOM is nothing but a POM with only a dependencyManagement section, where all these dependencies are listed with the correct version. That BOM is then included in each project's POM that should follow these dependencies/versions in its dependencyManagement section, with scope 'import'.

E.g.

You create your separate project 'my-bom', containing only a pom like this:

<project>
    
    <groupId>your.organication.program</groupId>
    <artifactId>my-bom</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.whatever</groupId>
                <artifactId>somedependency</artifactId>
                <version>1.2.3</version>
            </dependency>
            <dependency>
                <groupId>com.whatever</groupId>
                <artifactId>someotherdependency</artifactId>
                <version>4.5.6</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

And then you include that in each project that should be aligned with these dependencies/versions:

groupId>your.organication.program.project</groupId>
    <artifactId>some-project</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>your.organisation.program</groupId>
                <artifactId>my-bom</artifactId>
                <version>0.0.1-SNAPSHOT</version>
            </dependency>
    </dependencyManagement>

Within the projects the dependencies that are effectively used must still be referenced in dependencies-section, but without the version - the versions are managed by the BOM.

Bart Robeyns
  • 571
  • 4
  • 14