title: How can I specify --add-opens from a project level and make sure it is taken into account whatever the means to run my app?
body: <p>I've recently moved to Java 17 and with it came a couple restrictions requiring me to use <code>--add-opens</code> because of one dependency when running my application.</p>
  <p>I need to add this when the <code>java -jar</code> command is ran. For now I found these solutions:</p>
  <ul>
  <li>I can add it to the command line argument in my Dockerfile that runs the project</li>
  </ul>
  <pre><code>java --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/sun.util.calendar=ALL-UNNAMED -jar my.jar
  </code></pre>
  <ul>
  <li>I can add it in my MANIFEST.MF through my maven <code>pom.xml</code></li>
  </ul>
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
      &lt;configuration&gt;
          &lt;archive&gt;
              &lt;manifestEntries&gt;
                  &lt;Add-Opens&gt;java.base/sun.util.calendar java.base/java.util&lt;/Add-Opens&gt;
              &lt;/manifestEntries&gt;
          &lt;/archive&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  <p>Both work fine for production apparently. However when running my app through IntelliJ, it's not picking up the options which is normal I guess. I have to set them in my run configuration (which is also committed to my project by the way) as VM arguments.</p>
  <p><strong>I'm looking for a way to ensure consistency automatically and not have to maintain in parallel two places where I declare my add-opens.</strong></p>
  <p>EDIT: I'm wondering if something is doable with argfiles. Like have an argfile inside my project that would be referenced in the jar and that could be referenced in an y run configuration. I haven't found much evidence yet but that's the path I'm currently pursuing.</p>
  <p>EDIT 2: I added an <code>addopens</code> file at the root of my project and can now reference this from the various points where I need it. For tests, I added this and it worked out of the box with IntelliJ tests AND maven tests together:</p>
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
      &lt;configuration&gt;
          &lt;!-- This adds the options contained in the addopens file to the test JVM arguments --&gt;
          &lt;argLine&gt;@addopens @{argLine}&lt;/argLine&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  </code></pre>
  <p>I also can ship that <code>addopens</code> file in my docker to use in production. I still need to add to my Run configuration in IntteliJ the <code>@addopens</code> manually.</p>