title: How can I exclude a dependency from a POM built by the Gradle Maven Publishing plugin?
body: <p>I have the following dependencies in my <code>build.gradle</code>:</p>
  
  <pre class="lang-groovy prettyprint-override"><code>dependencies {
      compile 'org.antlr:antlr4-runtime:4.5.1'
      compile 'org.slf4j:slf4j-api:1.7.12'
      antlr "org.antlr:antlr4:4.5.1"
      testCompile group: 'junit', name: 'junit', version: '4.11'
      testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
      testCompile 'org.codehaus.groovy:groovy-all:2.4.4'
      testCompile 'cglib:cglib-nodep:3.1'
      testCompile 'org.objenesis:objenesis:2.1'
  }
  </code></pre>
  
  <p>When I use the Maven Publishing plugin to publish my library, it includes both the ANTLR runtime and compile time JARs as dependencies in the <a href="https://docs.gradle.org/current/userguide/publishing_maven.html#publishing_maven:generate-pom" rel="nofollow noreferrer">generated POM</a>:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;dependencies&gt;
    &lt;dependency&gt;                    &lt;!-- runtime artifact --&gt;
      &lt;groupId&gt;org.antlr&lt;/groupId&gt;
      &lt;artifactId&gt;antlr4-runtime&lt;/artifactId&gt;
      &lt;version&gt;4.5.1&lt;/version&gt;
      &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;                    &lt;!-- compile time artifact, should not be included --&gt;
      &lt;groupId&gt;org.antlr&lt;/groupId&gt;
      &lt;artifactId&gt;antlr4&lt;/artifactId&gt;
      &lt;version&gt;4.5.1&lt;/version&gt;
      &lt;scope&gt;runtime&lt;/scope&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>I only want the runtime library to be included in this POM.</p>
  
  <p>The culprit is the <code>antlr</code> dependency: If I remove this line, the generated POM does not have the compile-time dependency. However, then the build fails.</p>