title: How to add a non-modular Maven dependency to the module path as an automatic module?
body: <p>Lets say we would like to build a simple Java 11 modular Maven project with a single non-modular dependency <code>org.json:json</code> (picked at random for the sake of a practical example).</p>
  <p>Project structure:</p>
  <pre class="lang-none prettyprint-override"><code>project
  |-- pom.xml
  `-- src
      `-- main
          `-- java
              |-- foo.bar.project
              |   `-- foo
              |       `-- bar
              |           `-- project
              |               `-- Foo.java
              `-- module-info.java
  </code></pre>
  <p><strong><code>Foo.java</code></strong>:</p>
  <pre><code>package foo.bar.project;
  
  import org.json.JSONObject;
  
  public class Foo {
      static JSONObject o = new JSONObject();
  }
  </code></pre>
  <p><strong><code>module-info.java</code></strong>:</p>
  <pre><code>module foo.bar.project {
  }
  </code></pre>
  <p><strong><code>pom.xml</code></strong>:</p>
  <pre class="lang-xml prettyprint-override"><code>&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
    xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;foo.bar&lt;/groupId&gt;
    &lt;artifactId&gt;project&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  
    &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;maven.compiler.release&gt;11&lt;/maven.compiler.release&gt;
    &lt;/properties&gt;
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;org.json&lt;/groupId&gt;
        &lt;artifactId&gt;json&lt;/artifactId&gt;
        &lt;version&gt;20200518&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
  
    &lt;build&gt;
      &lt;pluginManagement&gt;
        &lt;plugins&gt;
          &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.8.1&lt;/version&gt;
            &lt;executions&gt;
              &lt;execution&gt;
                  &lt;goals&gt;
                      &lt;goal&gt;compile&lt;/goal&gt;
                  &lt;/goals&gt;
                  &lt;id&gt;compile&lt;/id&gt;
              &lt;/execution&gt;
            &lt;/executions&gt;
          &lt;/plugin&gt;
        &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  <hr />
  <p>My question is how to tell Maven to put <code>org.json</code> on the module path as an <em>automatic module</em>. By default, Maven places non-modular jars on the <code>classpath</code> as <em>unnamed modules</em>.</p>
  <p>As it stands, running <code>mvn clean compile</code> fails with:</p>
  <pre class="lang-none prettyprint-override"><code>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project project: Compilation failure
  [ERROR] &lt;PathToProject&gt;/src/main/java/foo.bar.project/foo/bar/project/Foo.java:[3,11] package org.json is not visible
  [ERROR]   (package org.json is declared in the unnamed module, but module org.json does not read it)
  [ERROR]
  [ERROR] -&gt; [Help 1]
  [ERROR]
  [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  [ERROR]
  [ERROR] For more information about the errors and possible solutions, please read the following articles:
  [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
  </code></pre>
  <hr />
  <p>System info:</p>
  <pre class="lang-none prettyprint-override"><code>Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-24T20:41:47+02:00)
  Maven home: C:\Tools\apache-maven-3.6.0
  Java version: 11.0.1, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11.0.1
  Default locale: sl_SI, platform encoding: UTF8
  OS name: &quot;windows 10&quot;, version: &quot;10.0&quot;, arch: &quot;amd64&quot;, family: &quot;windows&quot;
  </code></pre>