title: Dependening on legacy jar in Java 9 Module System library using gradle
body: <h2>Problem</h2>
  <p>How do you create a java library jar that both:</p>
  <ul>
  <li>is java module (has <code>module-info</code>)</li>
  <li>has a depending legacy (non-module) jar. (like <code>commons-exec</code>)?</li>
  </ul>
  <p>The dependency is an implementation detail - should not be exported.</p>
  <h2>Sources</h2>
  <p>Having the following <code>build.gradle</code> (using <code>gradle-6.8</code>):</p>
  <pre><code>plugins {
      id 'java-library'
  }
  
  group = 'test'
  version = '0.0.1-SNAPSHOT'
  sourceCompatibility = '15'
  
  repositories {
      mavenCentral()
  }
  java {
      modularity.inferModulePath = true
  }
  
  dependencies {
      implementation 'org.apache.commons:commons-exec:1.3'
  }
  </code></pre>
  <p>and the following <code>module-info.java</code>:</p>
  <pre><code>module test.module {
      requires commons.exec;
  }
  </code></pre>
  <h2>Errors</h2>
  <p>I'm getting the following compile error:</p>
  <pre><code>module-info.java:2: error: module not found: commons.exec
      requires commons.exec;
                      ^
  </code></pre>
  <p>If I don't include <code>requires commons.exec</code> then the error becomes:</p>
  <pre><code>error: package org.apache.commons.exec is not visible
  import org.apache.commons.exec.CommandLine;
                           ^
    (package org.apache.commons.exec is declared in the unnamed module,
     but module test.module does not read it)
  </code></pre>
  <h2><code>commons.exec</code> module name?</h2>
  <p>Running <code>jar --file=commons-exec-1.3.jar --describe-module </code> does output:</p>
  <pre><code>No module descriptor found. Derived automatic module.
  
  commons.exec@1.3 automatic
  requires java.base mandated
  contains org.apache.commons.exec
  contains org.apache.commons.exec.environment
  contains org.apache.commons.exec.launcher
  contains org.apache.commons.exec.util
  </code></pre>
  <p>So <code>commons.exec</code> looks like a valid module name for <code>commons-exec-1.3.jar</code>. Intelij Idea seem to agree and does auto-complete it in <code>module-info.java</code>. Though it fails at build time.</p>