Excluded dependence comes back when spring-boot plugin is applied

This is something the spring-boot plugin is doing through the Spring dependency-management-plugin: https://github.com/spring-gradle-plugins/dependency-management-plugin

The Spring dependency-management-plugin adds its own rules to force particular versions to be used, which ignores the exclusion you’ve added.

You can tell this by running gradle dependencyInsight --configuration compile --dependency elasticsearch

You should see something like:

org.elasticsearch:elasticsearch:1.5.2 (selected by rule)

org.elasticsearch:elasticsearch:2.0.0 -> 1.5.2
\--- project :module1
     \--- compile

org.springframework.data:spring-data-elasticsearch:1.3.2.RELEASE (selected by rule)

org.springframework.data:spring-data-elasticsearch:1.3.4.RELEASE -> 1.3.2.RELEASE
\--- project :module1
     \--- compile

The “selected by rule” part is the clue that there’s something programmatically selecting that version. If you run with --info, you’ll see output from the plugin describing all the versions it’s pinning.

You can get around this by adding your own rule. Instead of excluding and adding the correct version of elasticsearch, you can just configure Gradle to always replace the elasticsearch dependency with the correct one:

in the root project build.gradle:

allprojects {
    configurations.all {
        resolutionStrategy {
            dependencySubstitution {
                substitute module('org.elasticsearch:elasticsearch') with module('org.elasticsearch:elasticsearch:2.0.0')
            }
        }
    }
}

That tells Gradle to always substitute a dependency with group org.elasticsearch and name elasticsearch with the elasticsearch GAV for 2.0.0. Running dependencyInsight again should give you something like:

org.elasticsearch:elasticsearch:2.0.0 (selected by rule)

org.elasticsearch:elasticsearch:1.5.2 -> 2.0.0
\--- org.springframework.data:spring-data-elasticsearch:1.3.2.RELEASE
     \--- project :module1
          \--- compile

org.springframework.data:spring-data-elasticsearch:1.3.2.RELEASE (selected by rule)

org.springframework.data:spring-data-elasticsearch:1.3.4.RELEASE -> 1.3.2.RELEASE
\--- project :module1
     \--- compile

There may be other ways of configuring the Spring dependency-management-plugin, but I’m not familiar enough with it to suggest what that may be.