I have a Spring Boot 1.5.14 app that also pulls in a custom library we built that also relies on Spring Boot. This library (also Spring Boot 1.5.14) has some database utilities of sorts and in its build.gradle has:
compile 'org.postgresql:postgresql:42.2.2'
When I add that library to my apps compile dependencies, however, the actual version of the postgres driver that gets used (as seen from running `./gradlew dependencies in the app):
org.postgresql:postgresql:42.2.2 -> 9.4.1212.jre7
This end up causing a lot of debugging headache when the app couldn't actually open a jdbc connection to the postgres instance on AppEngine that I was trying to connect to. It sounds like the same problem described in this issue, since that postgres version is what's defined in the Spring Boot dependencies BOM.
I ended up working around this for now by adding compile 'org.postgresql:postgresql:42.2.2' directly into my app's build.gradle file... but I'd like to better understand why Spring Boot only downgraded that version when pulled in as a dependency of my library.
The behaviour that you have observed is due to the Dependency Management Plugin that Spring Boot's Gradle plugin uses for dependency management. When a dependency is declared in build.gradle with a version, it honours that version and ignores whatever version the configured dependency management may specify.
You can also override the dependency management by declaring a dependency and configuring it with the desired version. For example:
dependencies { compile 'com.google.guava:guava:18.0' }This will cause any dependency (direct or transitive) on
com.google.guava:guava:18.0in the compile configuration to use version 18.0, overriding any dependency management that may exist.
By specifying a version on its Postgres driver dependency, your library is overriding Boot's dependency management.
When you consume the library in another project, there's no such dependency so Spring Boot's dependency management is taking over. When you add the dependency on the driver (rather than relying on it coming in transitively), you're overriding the dependency management again.
An alternative approach would be to override the postgres.version property:
ext['postgres.version'] = '42.2.2'
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