'Gradle downgrading Hazelcast dependency when there's no other transitive dependency

I am using Gradle to include project A to my project B, where A has a dependency

implementation group: 'com.hazelcast', name: 'hazelcast', version: '5.0.2'

Then I include A in B's build.gradle file

implementation(group: '<group_name>', name: 'A', version: '0.2.0-SNAPSHOT') {
    exclude group: 'org.slf4j'
    }

However, when building the project, Hazelcast is getting downgraded somehow. Dependency tree:

    (base) (my name) B % ./gradlew dependencies | grep hazelcast
     +--- com.hazelcast:hazelcast:5.0.2 -> 4.0.3
     +--- com.hazelcast:hazelcast:5.0.2 -> 4.0.3
     +--- com.hazelcast:hazelcast:5.0.2 -> 4.0.3
I commented out all other dependencies in B, to make sure there's no other transitive dependency, but gradle still chooses a lower version of Hazelcast out of no where. Project A build with correct version of Hazelcast 5.0.2. 

I am now forcing the version by adding Hazelcast dependency explicitly in B

implementation group: 'com.hazelcast', name: 'hazelcast', version: '5.0.2'

But would love to know the root cause for a formal fix. Does anyone have similar issue, or know why this is happening?



Solution 1:[1]

It's likely a Spring plugin managing your dependency to 4.0.3.

Try the following:

ext['hazelcast.version'] = '5.0.2'

See https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#managing-dependencies.dependency-management-plugin.customizing

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 FrantiĊĦek Hartman