title: Module not found: How to compile JDK 10 Eclipse Maven Project with Module?
body: <p>Followings are the main sections of my pom.xml:</p>
  
  <p><strong>properties:</strong></p>
  
  <pre><code>&lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;project.build.targetEncoding&gt;UTF-8&lt;/project.build.targetEncoding&gt;
      &lt;jdk.release&gt;10&lt;/jdk.release&gt;
      &lt;jdk.vendor&gt;oracle&lt;/jdk.vendor&gt;
      &lt;maven.compiler.source&gt;1.10&lt;/maven.compiler.source&gt;
      &lt;maven.compiler.target&gt;1.10&lt;/maven.compiler.target&gt;
  
      &lt;dependency.asm.version&gt;6.2&lt;/dependency.asm.version&gt;
      &lt;dependency.log4j2.version&gt;2.11.0&lt;/dependency.log4j2.version&gt;
  
      &lt;plugin.maven-toolchains.version&gt;1.1&lt;/plugin.maven-toolchains.version&gt;
      &lt;plugin.maven-compiler.version&gt;3.7.0&lt;/plugin.maven-compiler.version&gt;    
      &lt;plugin.maven-dependency.version&gt;3.1.1&lt;/plugin.maven-dependency.version&gt;
      &lt;plugin.maven-jar.version&gt;3.1.0&lt;/plugin.maven-jar.version&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p><strong>dependencies</strong>:</p>
  
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
          &lt;version&gt;${dependency.log4j2.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
          &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
          &lt;version&gt;${dependency.log4j2.version}&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p><strong>plugins</strong>:</p>
  
  <pre><code>&lt;plugins&gt;
      &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-toolchains-plugin&lt;/artifactId&gt;
          &lt;version&gt;${plugin.maven-toolchains.version}&lt;/version&gt;
          &lt;executions&gt;
              &lt;execution&gt;
                  &lt;goals&gt;
                      &lt;goal&gt;toolchain&lt;/goal&gt;
                  &lt;/goals&gt;
              &lt;/execution&gt;
          &lt;/executions&gt;
          &lt;configuration&gt;
              &lt;toolchains&gt;
                  &lt;jdk&gt;
                      &lt;version&gt;${jdk.release}&lt;/version&gt;
                      &lt;vendor&gt;${jdk.vendor}&lt;/vendor&gt;
                  &lt;/jdk&gt;
              &lt;/toolchains&gt;
          &lt;/configuration&gt;
      &lt;/plugin&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;${plugin.maven-compiler.version}&lt;/version&gt;
          &lt;configuration&gt;
              &lt;source&gt;${maven.compiler.source}&lt;/source&gt;
              &lt;target&gt;${maven.compiler.target}&lt;/target&gt;
              &lt;release&gt;${jdk.release}&lt;/release&gt;
          &lt;/configuration&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.ow2.asm&lt;/groupId&gt;
                  &lt;artifactId&gt;asm&lt;/artifactId&gt;
                  &lt;version&gt;${dependency.asm.version}&lt;/version&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-dependency-plugin&lt;/artifactId&gt;
          &lt;version&gt;${plugin.maven-dependency.version}&lt;/version&gt;
          &lt;executions&gt;
              &lt;execution&gt;
                  &lt;id&gt;copy-dependencies&lt;/id&gt;
                  &lt;phase&gt;package&lt;/phase&gt;
                  &lt;goals&gt;
                      &lt;goal&gt;copy-dependencies&lt;/goal&gt;
                  &lt;/goals&gt;
                  &lt;configuration&gt;
                      &lt;outputDirectory&gt;${project.basedir}/dist/lib/&lt;/outputDirectory&gt;
                  &lt;/configuration&gt;
              &lt;/execution&gt;
          &lt;/executions&gt;
      &lt;/plugin&gt;
      &lt;plugin&gt;
          &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
          &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
          &lt;version&gt;${plugin.maven-jar.version}&lt;/version&gt;
          &lt;configuration&gt;
              &lt;archive&gt;
                  &lt;manifest&gt;
                      &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                      &lt;classpathPrefix&gt;./lib/&lt;/classpathPrefix&gt;
                      &lt;mainClass&gt;com.mycompany.tbe.myproject.Application&lt;/mainClass&gt;
                      &lt;addDefaultImplementationEntries&gt;true&lt;/addDefaultImplementationEntries&gt;
                      &lt;addDefaultSpecificationEntries&gt;true&lt;/addDefaultSpecificationEntries&gt;
                  &lt;/manifest&gt;
              &lt;/archive&gt;
              &lt;descriptorRefs&gt;
                  &lt;descriptorRef&gt;jar-with-dependencies&lt;/descriptorRef&gt;
              &lt;/descriptorRefs&gt;
              &lt;outputDirectory&gt;${project.basedir}/dist&lt;/outputDirectory&gt;
          &lt;/configuration&gt;
      &lt;/plugin&gt;       
  &lt;/plugins&gt;
  </code></pre>
  
  <p>The project structure is:</p>
  
  <pre><code>project
  +
  |-- src
  |   +
  |   |-- main
  |   |   +
  |   |   |-- java
  |   |   |   +
  |   |   |   |-- com
  |   |   |   |   +
  |   |   |   |   |-- mycompany
  |   |   |   |   |   +
  |   |   |   |   |   |-- tbe
  |   |   |   |   |   |   +
  |   |   |   |   |   |   |-- myproject
  |   |   |   |-- module-info.java
  |   |   |-- resources    
  |-- pom.xml
  </code></pre>
  
  <p>The <code>module-info.java</code> contains:</p>
  
  <pre><code>/**
   * @author Tapas Bose
   */
  module project {
      exports com.mycompany.tbe.myproject;
  
      requires log4j.api;
  }
  </code></pre>
  
  <p>When I'm executing: <code>mvn clean package</code> it is throwing error, telling:</p>
  
  <pre><code>[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project &lt;my-project&gt;: Compilation failure
  [ERROR] &lt;path-to-my-project&gt;/src/main/java/module-info.java:[7,15] error: module not found: log4j.api
  </code></pre>
  
  <p>I also have tried to supply <code>--add-modules</code> argument into the <code>maven-compiler-plugin</code> by specifying configuration:</p>
  
  <pre><code>&lt;configuration&gt;
      &lt;compilerArgs&gt;
          &lt;arg&gt;--add-modules&lt;/arg&gt;
          &lt;arg&gt;log4j.api&lt;/arg&gt;
      &lt;/compilerArgs&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>But that didn't work either.</p>
  
  <p>Few points:</p>
  
  <p>If I delete the <code>module-info.java</code> it works.</p>
  
  <p>The <code>module-info.java</code> is generated by Eclipse.</p>
  
  <p>The <code>java describe-module</code> reveals the followings:</p>
  
  <pre><code>$ jar --file=log4j-api-2.11.0.jar --describe-module
  releases: 9
  
  No root module descriptor, specify --release
  
  $ jar --file=log4j-api-2.11.0.jar --describe-module --release 9
  releases: 9
  
  org.apache.logging.log4j jar:file:///&lt;path-to-maven-local-repository&gt;/org/apache/logging/log4j/log4j-api/2.11.0/log4j-api-2.11.0.jar/!META-INF/versions/9/module-info.class
  exports org.apache.logging.log4j
  exports org.apache.logging.log4j.message
  exports org.apache.logging.log4j.simple
  exports org.apache.logging.log4j.spi
  exports org.apache.logging.log4j.status
  exports org.apache.logging.log4j.util
  requires java.base mandated
  uses org.apache.logging.log4j.message.ThreadDumpMessage$ThreadInfoFactory
  uses org.apache.logging.log4j.spi.Provider
  uses org.apache.logging.log4j.util.PropertySource
  </code></pre>
  
  <p>Hence if change the <code>module-info.java</code> as:</p>
  
  <pre><code>/**
   * @author Tapas Bose
   */
  module project {
      exports com.mycompany.tbe.myproject;
  
      requires org.apache.logging.log4j;
  }
  </code></pre>
  
  <p>Eclipse Java Editor starts showing compilation error in the file <code>module-info.java</code>: </p>
  
  <p><a href="https://i.stack.imgur.com/DmquW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DmquW.png" alt="enter image description here"></a></p>
  
  <p>Also in other Java classes where log4j-api's packages are used:</p>
  
  <p><a href="https://i.stack.imgur.com/A8RxF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A8RxF.png" alt="enter image description here"></a></p>
  
  <p>But <code>mvn clean package</code> works in this case with warning messages:</p>
  
  <pre><code>[WARNING] ********************************************************************************************************************
  [WARNING] * Required filename-based automodules detected. Please don't publish this project to a public artifact repository! *
  [WARNING] ********************************************************************************************************************
  </code></pre>
  
  <p>I'm using:</p>
  
  <ul>
  <li>Eclipse Oxygen.3a Release (4.7.3a)</li>
  <li>Oracle JDK 10</li>
  <li>Apache Maven 3.5.2 </li>
  </ul>
  
  <p>In another SO thread: <a href="https://stackoverflow.com/questions/50196952/spring-boot-module-not-found-error">Spring Boot module not found error</a> it is asked to clean maven's local-repository. I also tried to do the same using <code>mvn clean dependency:purge-local-repository package</code>, but no luck.</p>