title: Gradle Dependency Management - Transitive Dependency Version Incorrect
body: <p>I have two projects edited in IntelliJ IDEA 2016 that use Gradle dependency management: project A and project B.</p>
  
  <p>Project A defines a compile scope dependency for elasticsearch as:</p>
  
  <pre><code>    compile 'org.elasticsearch:elasticsearch:2.3.1'
  </code></pre>
  
  <p>Project B declares a compile scope dependency for project A, as so:</p>
  
  <pre><code>    compile 'com.mycompany:elasticsearch-common:2.3.1'
  </code></pre>
  
  <p>I would expect, in the Gradle tool window in IntelliJ IDEA 2016, for project B to see:</p>
  
  <pre><code>...
  com.mycompany:elasticsearch-common:2.3.1 (Compile)
      org.elasticsearch:elasticsearch:2.3.1 (Compile)
  ...
  </code></pre>
  
  <p>Instead I see:</p>
  
  <pre><code>...
  com.mycompany:elasticsearch-common:2.3.1 (Compile)
      org.elasticsearch:elasticsearch:1.5.2 (Compile)
  ...
  </code></pre>
  
  <p>No other dependency in project B depends on elasticsearch, so it's not being overridden by another dependency declaration.</p>
  
  <p>Indeed, the pom.xml on our nexus for project A has this:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.elasticsearch&lt;/groupId&gt;
      &lt;artifactId&gt;elasticsearch&lt;/artifactId&gt;
      &lt;version&gt;2.3.1&lt;/version&gt;
      &lt;scope&gt;compile&lt;/scope&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>So why is IntelliJ reporting the transitive version for elasticsearch as being 1.5.2?</p>
  
  <p>What I've tried:</p>
  
  <ol>
  <li>Deleting .idea and .gradle inside project B directory</li>
  <li>Deleting gradle caches </li>
  <li>Invalidating caches and restarting in IntelliJ </li>
  <li>Swearing</li>
  <li>Drinking lots of tea</li>
  <li>Asking friends and colleagues </li>
  <li>Emailing Oprah</li>
  <li>Reverting to IntelliJ 15 when all of this was fine (now no longer is)</li>
  <li>Going to the toilet (related to 5) and hoping it magically fixes itself when I get back</li>
  </ol>
  
  <p>None of the above work. </p>
  
  <p>What does work is specifying the <code>elasticsearch:2.3.1</code> dependency specifically in project B, but doesn't that negate the entire reason for transitive dependencies?</p>
  
  <p>Any help is appreciated.</p>
  
  <p><strong>Update 1</strong><br />
  As suggested by LanceJava in the comments, I ran <code>gradle dependencies</code> to see what was happening.</p>
  
  <p>This shows that it's specifically downgrading it:</p>
  
  <pre><code>org.elasticsearch:elasticsearch:2.3.1 -&gt; 1.5.2
  </code></pre>
  
  <p>When I ran gradle dependencyInsight on that dependency it came up with:</p>
  
  <pre><code>:dependencyInsight
  com.mycompany:elasticsearch-common:2.3.1 (selected by rule)
  \--- compile
  
  org.elasticsearch:elasticsearch:1.5.2 (selected by rule)
  
  org.elasticsearch:elasticsearch:2.3.1 -&gt; 1.5.2
  \--- com.mycompany:elasticsearch-common:2.3.1
       \--- compile
  </code></pre>
  
  <p>Anyone have any ideas why this is happening?</p>
  
  <p><strong>Update 2</strong><br />
  This seems to have the answer: <a href="https://discuss.gradle.org/t/excluded-dependence-comes-back-when-spring-boot-plugin-is-applied/17945/2" rel="nofollow">https://discuss.gradle.org/t/excluded-dependence-comes-back-when-spring-boot-plugin-is-applied/17945/2</a></p>
  
  <p>It seems that the gradle spring-boot plugin likes to take over a bit and enforce it's own dependency versions (even though I'm not using a spring-boot-starter that is using spring-data).</p>
  
  <p>I fixed this by adding:</p>
  
  <pre><code>ext[elasticsearch.version] = '2.3.1'
  </code></pre>
  
  <p>to my build.gradle file.</p>