title: How to exclude a Maven test-scoped dependency from Eclipse (but keep it in the path for unit tests)
body: <p>I am having some problems getting Eclipse to honour a test-scoped Maven dependency - it is showing up on the build path and messing with eclipse's compilation / javadoc resolution.</p>
  
  <h3>An example with Java EE libs</h3>
  
  <p>I have been using the <code>javaee-api-6.0</code> library to compile my Java EE application against. </p>
  
  <p>However, for unit testing purposes, I wanted to have access to more than just the api - I needed an implementation. So I included the embedded glassfish libs with a test scope like so:</p>
  
  <pre><code>&lt;repositories&gt;
      &lt;repository&gt;
          &lt;id&gt;glassfish-extras-repository&lt;/id&gt;
          &lt;url&gt;http://download.java.net/maven/glassfish/org/glassfish/extras&lt;/url&gt;
      &lt;/repository&gt;
  &lt;/repositories&gt;
  
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.glassfish.extras&lt;/groupId&gt;
          &lt;artifactId&gt;glassfish-embedded-all&lt;/artifactId&gt;
          &lt;version&gt;3.1.1&lt;/version&gt;
          &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax&lt;/groupId&gt;
          &lt;artifactId&gt;javaee-api&lt;/artifactId&gt;
          &lt;version&gt;6.0&lt;/version&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
          &lt;type&gt;jar&lt;/type&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <h3>Works as expected with Maven</h3>
  
  <p>From my understanding, because of the <code>&lt;scope&gt;test&lt;/scope&gt;</code> of the glassfish dependency, it will not be included in the regular <code>compile</code> phase. </p>
  
  <p>Because both dependencies would be included in the <code>test-compile</code> phase, I was sure to place the glassfish dependency before the javaee-api dependency so that the former would be used in preference to the latter when compiling the test classes. And so, when using just Maven to build, this configuration is not a problem.</p>
  
  <h3>Does not work as expected within Eclipse</h3>
  
  <p>However, when using m2e and Eclipse, the glassfish dependency is listed in my build path:</p>
  
  <p><img src="https://i.stack.imgur.com/nluHG.png" alt="dependency listed on build path"></p>
  
  <p>Because the glassfish dependency is listed before the java-ee-api dependency, it appears that Eclipse is using the wrong lib (glassfish, instead of the java-ee-api) to validate / compile / look up javadocs. (Actually, I am not 100% sure that compilation is using the wrong lib - it depends on whether under the hood Eclipse is using Maven to perform the compilation used when validating code, and I don't know if it is or not - but the javadoc lookup is definitely referencing the wrong lib)</p>
  
  <h3>The Question</h3>
  
  <p>How can I stop Eclipse from using the glassfish lib except for when running unit tests? I want to ensure my compilation / javadoc lookups are ocurring on the api, not a particular implementation of that api.</p>