Gradle - Force sub dependencies version

Viewed 2652

We have an old application which is using Gradle 4.5. Someone has added dependencies without explicit version.

So now I have some sub dependencies with version conflict. Is there a way to force sub dependencies versions?

I have tried the code below but it does not work:

configurations.all {
    resolutionStrategy {
        force 'com.amazonaws:aws-java-sdk-dynamodb:1.11.390'
    }  
}
1 Answers

You should be able to use either strictly or force here. Reading:

https://docs.gradle.org/current/userguide/dependency_downgrade_and_exclude.html

should help. The manual describes more or less exactly your scenario.

<< edit after comments >>

Forgot you were using gradle 4.5, I don't think you have strictly and force available to you.

Another way is to exclude the transitive dependency when you define the dependency which pulls in the wrong version:

apply plugin: "java"

repositories { 
  mavenCentral()
}

dependencies { 
  compile('whatever-dependency:is-pulling-in-wrong-version:1.0.0') {
    exclude group: 'com.amazonaws', module: 'aws-java-sdk-dynamodb'
  }
  compile 'com.amazonaws:aws-java-sdk-dynamodb:1.11.390'
}

this should exclude the dynamo dependency from the transitive tree of the other library and leave you with the version you specifically ask for.

Related