title: Gradle java-library plugin compared to java plugin
body: <p>In the Gradle documentation for the <a href="https://docs.gradle.org/current/userguide/java_library_plugin.html" rel="noreferrer">java-library plugin</a> it states:</p>
  
  <blockquote>
    <p>The Java Library plugin expands the capabilities of the Java plugin by providing specific knowledge about Java libraries. In particular, a Java library exposes an API to consumers (i.e., other projects using the Java or the Java Library plugin)</p>
  </blockquote>
  
  <p>This statement implies that only java programs that are meant to be consumed (libraries) should use the <code>java-library</code> plugin; while, java programs that are not meant to be consumed (applications) should use the <code>java</code> plugin.</p>
  
  <p>Prior to using the <code>java-library</code> plugin a root <code>build.gradle</code> file could contain the following:</p>
  
  <pre><code>subprojects {
      apply plugin: 'java'
      sourceCompatibility '1.8'
      targetCompatibility '1.8'
  
      // other common java stuff
  }
  </code></pre>
  
  <p>However now in multi module projects that has both applications and libraries you cannot delegate the plugin selection to the sub projects and have the following root <code>build.gradle</code>:</p>
  
  <pre><code>subprojects {
      sourceCompatibility '1.8'
      targetCompatibility '1.8'
  
      // other common java stuff
  }
  </code></pre>
  
  <p>This will fail because <code>sourceCompatibility</code> and <code>targetCompatibility</code> are defined by the <code>java</code> and <code>java-library</code> plugins. Ideally I would like to do the following:</p>
  
  <pre><code>subprojects {
      apply plugin: 'java-library'
      sourceCompatibility '1.8'
      targetCompatibility '1.8'
  
      // other common java stuff
  }
  </code></pre>
  
  <p>Is there any reason to enforce that java applications use the <code>java</code> plugin and that java libraries use the <code>java-library</code> plugin? Is there any reason that the <code>java</code> plugin should be used instead of the <code>java-library</code> plugin?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>To further clarify my question, in the Gradle samples there is a multi module project for with the <code>java</code> plugin <a href="https://github.com/gradle/gradle/tree/master/subprojects/docs/src/samples/java/multiproject" rel="noreferrer">here</a> and for the <code>java-library</code> plugin <a href="https://github.com/gradle/gradle/tree/master/subprojects/docs/src/samples/java-library/multiproject" rel="noreferrer">here</a>. In the sample for the <code>java</code> plugin, the root build.grade uses <code>apply plugin: 'java'</code>. The root build.gradle for the <code>java-library</code> plugin does not use any plugins. The app project uses <code>apply plugin: 'java'</code>; while, the core and utils projects use <code>apply plugin: 'java-library'</code>. </p>
  
  <p>My question is why should some projects use the <code>java</code> plugin and others use the <code>java-library</code> plugin? Its seems to make it more difficult to not violate the DRY principle. I makes it difficult to specify the <code>sourceCompatibility</code> and <code>targetCompatibility</code> only once. I can think of a few ways specify these properties once, but the simplest solution seems to be using the <code>java-library</code> for all projects.</p>
  
  <p>Is there any benefit to using the <code>java</code> plugin for some sub projects and the <code>java-library</code> plugin for others?</p>