title: module-info.class file is different in the module jar file and compiled module-info.class
body: <p>I have a simple module I'm building with <code>maven</code> and have a question about the resulting module jar. Here is the plugin section of my <code>pom.xml</code>:</p>
  
  <pre><code>&lt;properties&gt;
      &lt;java.version&gt;11&lt;/java.version&gt;
      &lt;maven.compiler.plugin.version&gt;3.8.0&lt;/maven.compiler.plugin.version&gt;
      &lt;maven.jar.plugin.version&gt;3.1.2&lt;/maven.jar.plugin.version&gt;
  &lt;/properties&gt;
  
  &lt;build&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;${maven.compiler.plugin.version}&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;release&gt;${java.version}&lt;/release&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
      &lt;pluginManagement&gt;
          &lt;plugins&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;${maven.jar.plugin.version}&lt;/version&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>The project has the following structure:</p>
  
  <pre><code>mdl-standalone
      |
      |
      |__src/main/java
      |     |_com/test/mdl
      |     |     |_platform/Platform.java
      |     |     |_standalone/Standalone.java     
      |     |
      |     |_module-info.java
      |_pom.xml
  </code></pre>
  
  <p><code>module-info.java</code>:</p>
  
  <pre><code>module com.test.mdl.standalone {
  }
  </code></pre>
  
  <p>The <code>mvn clean install</code> command builds jar file and put compiled class files in the <code>target/classes</code> directory. I examined the following class files and noticed some difference:</p>
  
  <p><code>javap -v target/classes/module-info.class</code> (constant pool only)</p>
  
  <pre><code>  interfaces: 0, fields: 0, methods: 0, attributes: 2
  Constant pool:
     #1 = Class              #8             // "module-info"
     #2 = Utf8               SourceFile
     #3 = Utf8               module-info.java
     #4 = Utf8               Module
     #5 = Module             #9             // "com.test.mdl.standalone"
     #6 = Module             #10            // "java.base"
     #7 = Utf8               11.0.4
     #8 = Utf8               module-info
     #9 = Utf8               com.test.mdl.standalone
    #10 = Utf8               java.base
  </code></pre>
  
  <p><code>javap -v</code> of <code>module-info.class</code> extracted from the jar file:</p>
  
  <pre><code>  interfaces: 0, fields: 0, methods: 0, attributes: 3
  Constant pool:
     #1 = Utf8               module-info
     #2 = Class              #1             // "module-info"
     #3 = Utf8               module-info.java
     #4 = Utf8               com.test.mdl.standalone
     #5 = Module             #4             // "com.test.mdl.standalone"
     #6 = Utf8               ModulePackages
     #7 = Utf8               com/test/mdl/standalone
     #8 = Package            #7             // com/test/mdl/standalone
     #9 = Utf8               com/test/mdl/platform
    #10 = Package            #9             // com/test/mdl/platform
    #11 = Utf8               java.base
    #12 = Module             #11            // "java.base"
    #13 = Utf8               11.0.4
    #14 = Utf8               SourceFile
    #15 = Utf8               Module
  </code></pre>
  
  <p>As can be seen there are difference in the constant pool and attribute numbers. In particular the <code>module-info.class</code> from the jar file contains <a href="https://docs.oracle.com/javase/specs/jvms/se12/html/jvms-4.html#jvms-4.7.26" rel="nofollow noreferrer"><code>ModulePackages</code></a> attribute with all the packages of the module packed within the jar.</p>
  
  <p>This has some impact on determining the packages returned by <code>ModuleDescriptor::packages()</code>. In <code>case 2</code> the packages are simply extracted from the <code>ModulePackages</code> attribute the <code>case 1</code> in turn requires listing the directory tree and extracting package names.</p>
  
  <p><strong><em>QUESTION:</em></strong> Which plugin sets the <code>ModulePackages</code> attribute of <code>module-info.class</code> in the jar file? </p>
  
  <p>I suspect it is the <code>maven-jar-plugin</code>'s job, but how to configure it? In case, e.g. I want to reduce <code>module-info.class</code> size.</p>