title: Combination of module path and class path with Gradle
body: <p>The Java Platform Module system allows to add dependencies both on the module path and the class path:</p>
  
  <pre><code>java --add-modules java.sql \
       --add-opens java.base/java.lang=javassist \
       -p mytarget/lib-direct:mytarget/cqrs.jar \
       -cp "mytarget/lib/*" \
       -m com.iluwatar.cqrs/com.iluwatar.cqrs.app.App
  </code></pre>
  
  <p>(<a href="https://dzone.com/articles/a-practical-guide-to-java-9-migration" rel="nofollow noreferrer">dzone.com</a>)</p>
  
  <p>In the Gradle Guide for using the Java modules it is shown how to transform everything from the classpath into anonymous modules:</p>
  
  <pre><code>compileJava {
      inputs.property("moduleName", moduleName)
      doFirst {
          options.compilerArgs = [
              '--module-path', classpath.asPath,
          ]
          classpath = files()  
      }
  }
  </code></pre>
  
  <p>(<a href="https://guides.gradle.org/building-java-9-modules/" rel="nofollow noreferrer">guides.gradle.org</a>)</p>
  
  <p>This may not be applicable when the dependencies do not comply with the JPMS restrictions like the prohibition of split packages.</p>
  
  <p>I tried to enforce the usage of the class path by stating this explicitly but it didn't help:</p>
  
  <pre><code>compileJava {
      doFirst {
          options.compilerArgs = [
                  '-cp', classpath.asPath
          ]
      }
  }
  </code></pre>
  
  <p>The problem can be reproduced in here: <a href="https://github.com/jmewes/jpms-gradle" rel="nofollow noreferrer">https://github.com/jmewes/jpms-gradle</a></p>
  
  <p>The build of this project will lead to a compilation failure because the external dependencies are not included in the <code>module-info.java</code> files. Those compilation failures can be fixed by adding <code>require</code> statements with the automatic module names for the different dependencies (e.g. with the auto-assist of IntelliJ) like this:</p>
  
  <pre><code>module billing {
      requires spring.context;
  
      exports com.experimental.billing.api;
  }
  </code></pre>
  
  <p>However, the compilation will fail in a later step due to the JPMS restrictions:</p>
  
  <pre><code>Error:java: the unnamed module reads package javax.transaction from both javax.transaction.api and jboss.transaction.api.1.2.spec
  </code></pre>
  
  <p>Is it possible to use the module path only for the dependencies on the internal sub-modules of the project and the class path for all external dependencies?
  If yes, how can this be done with Gradle?</p>