title: Gradle automatic module dependency
body: <p>tldr: gradle x java library without a <code>module-info.class</code></p>
  <p>I have a Gradle project in which i'd like to use the Java <a href="https://github.com/openjdk/jol" rel="nofollow noreferrer">JOL</a> library, so i added the following to the <code>build.gradle</code> file:</p>
  <pre><code>dependencies {
      implementation 'org.openjdk.jol:jol-core:0.16'
  }
  </code></pre>
  <p>I also added <code>requires jol.core;</code> to my project's <code>module-info.java</code> (which Intellij shows for autocompletion), however when running the project, I get an error:</p>
  <pre><code>&gt; Task :[MainClass].main() FAILED
  Error occurred during initialization of boot layer
  java.lang.module.FindException: Module jol.core not found, required by [the project module]
  </code></pre>
  <p>I thought this was because the jar does not seem to seem to include a <code>module-info.class</code>, but after looking at the other dependencies, I noticed that i am also using the <a href="https://github.com/ronmamo/reflections" rel="nofollow noreferrer">reflections</a> library without any problem, and its jar does not contain a <code>module-info.class</code> file.</p>
  <p>So far, I've tried <a href="https://docs.gradle.org/7.0/userguide/java_library_plugin.html#using_libraries_that_are_not_modules" rel="nofollow noreferrer">'Using libraries that are not modules'</a> from the Gradle docs, i.e removing the <code>requires jol.core</code> line, but then I get the error that it belongs to the unnamed module and as such it cannot be read from my own module. So i followed the instructions about making it an automatic module with (from the docs)</p>
  <pre><code>tasks.named('jar') {
      manifest {
          attributes('Automatic-Module-Name': 'org.gradle.sample')
      }
  }
  
  </code></pre>
  <p>but it still didn't work. I've also tried toggling on and off</p>
  <pre><code>java {
      modularity.inferModulePath = true
  }
  </code></pre>
  <p>which didn't seem to help. I also tried to add a <code>Automatic-Module-Name</code> field to the manifest file, but it still didn't work.</p>
  <p>Now I managed to get it working thanks to the gradle plugin <a href="https://github.com/jjohannes/extra-java-module-info" rel="nofollow noreferrer">Extra java module info</a>, but it leaves me with a few questions.</p>
  <p>Out of curiosity, I created a new, empty Gradle project and only added JOL as a dependency and it didn't work; but when I created a Maven project, it worked out of the box, without the need to use an external plugin, simply by adding to my <code>pom.xml</code></p>
  <pre><code>&lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.openjdk.jol&lt;/groupId&gt;
          &lt;artifactId&gt;jol-core&lt;/artifactId&gt;
          &lt;version&gt;0.16&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  </code></pre>
  <p>So now I'm wondering what did I miss that made it not work with gradle? Is there a better way than using the extra module info plugin and exporting all the packages I need? And why would it work with the Reflections lib, but not JOL?</p>