title: Exclude maven sub modules dependencies from top level module
body: <p>I created a maven parent project with three modules :  </p>
  
  <ul>
  <li>data-layer-module</li>
  <li>data-service-module (uses the data-layer-module)</li>
  <li>web-module (uses the data-services-module)</li>
  </ul>
  
  <p>Here is a snippet from the parent pom.xml :  </p>
  
  <pre><code>&lt;groupId&gt;org.mygroup&lt;/groupId&gt;
  &lt;artifactId&gt;myArtifact&lt;/artifactId&gt;
  &lt;packaging&gt;pom&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
  &lt;modules&gt;
    &lt;module&gt;data-layer-module&lt;/module&gt;
    &lt;module&gt;data-service-module&lt;/module&gt;
    &lt;module&gt;web-module&lt;/module&gt;
  &lt;/modules&gt; 
  </code></pre>
  
  <p>The <code>data-layer-module</code> <code>pom.xml</code> contains no dependencies to the other modules (it contains only its external dependencies).  </p>
  
  <p>The <code>data-service-module</code> has a dependency in its <code>pom.xml</code> to the <code>data-layer-module</code> :  </p>
  
  <pre><code>&lt;dependencies&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.mygroup&lt;/groupId&gt;
            &lt;artifactId&gt;data-layer-module&lt;/artifactId&gt;
            &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
        &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>And the <code>web-module</code> has a dependency to the <code>data-service-module</code> :  </p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.mygroup&lt;/groupId&gt;
      &lt;artifactId&gt;data-service-module&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  
  <p>Everything is fine but I don't want the <code>web-module</code> to have access to the <code>data-layer-module</code>. I need to enforce the three layer web-service-data model. Which is not the case with this configuration.<br>
  I obviously tried manually excluding it from the <code>web-module</code> <code>pom.xml</code> :  </p>
  
  <pre><code>&lt;dependency&gt;
      &lt;groupId&gt;org.mygroup&lt;/groupId&gt;
      &lt;artifactId&gt;data-service-layer&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;exclusions&gt;
          &lt;exclusion&gt;
              &lt;groupId&gt;org.mygroup&lt;/groupId&gt;
              &lt;artifactId&gt;data-layer-module&lt;/artifactId&gt;
          &lt;/exclusion&gt;
      &lt;/exclusions&gt;
  &lt;/dependency&gt;  
  </code></pre>
  
  <p>But this causes compilation error since the <code>data-service-module</code> can't find its <code>data-layer-module</code> dependency. </p>
  
  <p>How could this configuration be done ?</p>