title: Resolve duplicate versions of dependency
body: <p>This has been very annoying. I have 2 projects, project <code>A</code> and <code>B</code>, <code>B</code> with dependency on <code>A</code> as a JAR file. So a 3rd library <code>X</code> in A has a dependency on another 3rd party library <code>Y</code>, the problem is maven resolves <code>Y</code> in project <code>A</code> to a version, but in project <code>B</code> to another version, like the following:</p>
  
  <pre><code>commons-beanutils:jar:1.9.2 vs. commons-beanutils:jar:1.8.0
  </code></pre>
  
  <p>And the version below is specified in project <code>A</code>:</p>
  
  <pre><code>net.sf.json-lib:json-lib:jar:jdk15:2.4
  </code></pre>
  
  <p>In the POM.xml of project <code>B</code>, there isn't really any explicitly specified version of dependencies.</p>
  
  <p>In project <code>A</code>:</p>
  
  <pre><code>[INFO] +- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile
  [INFO] |  +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
  [INFO] |  +- commons-collections:commons-collections:jar:3.2.1:compile
  [INFO] |  \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
  </code></pre>
  
  <p>In project <code>B</code> that only introduces the dependency on <code>Y</code> because of <code>A</code>:</p>
  
  <pre><code>[INFO] +- A.jar
  [INFO] |  +- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile
  [INFO] |  |  +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
  [INFO] |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
  [INFO] |  |  \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
  </code></pre>
  
  <p>The ideal solution is to only make changes in <code>pom.xml</code> in project <code>B</code> to solve the duplicate versions dependency hell. Any idea? Thanks!</p>
  
  <p>Is it possible to make project <code>B</code> inherit dependencies from <code>A.jar</code> instead of introducing those of its own.</p>
  
  <h1>EDIT</h1>
  
  <p>In the end I found something that worked, so I'd just put it here in case someone may be facing the same problem later.</p>
  
  <p>The key is to put the dependencies come with project A into exclusions, so maven won't just use the versions of libraries defined in project A, but work out a version based on the current context. Below is the example:</p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;com.wonderland&lt;/groupId&gt;
      &lt;artifactId&gt;project-a&lt;/artifactId&gt;
      &lt;version&gt;1.0&lt;/version&gt;
      &lt;exclusions&gt;
          &lt;exclusion&gt;
              &lt;groupId&gt;commons-beanutils&lt;/groupId&gt;
              &lt;artifactId&gt;commons-beanutils&lt;/artifactId&gt;
          &lt;/exclusion&gt;
          &lt;!-- ... everything else to be excluded --&gt;
      &lt;exclusions&gt;
  &lt;/dependency&gt;
  </code></pre>