<div dir="ltr">I'm seeing a runtime error I was not expecting.<div><br></div><div><i>Error occurred during initialization of boot layer<br>java.lang.module.ResolutionException: Module io.avaje.config does not read a module that exports io.avaje.inject.spi</i><br></div><div><br></div><div><br></div><div>The module io.avaje.config has a requires static io.avaje.inject , and that io.avaje.inject<span class="gmail-Apple-converted-space"> </span>module exports the interface used in the provides clause.</div><div><br></div><div><p style="margin:0px 0px 0px 28.9px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(128,0,128)"><span style="font-variant-ligatures:no-common-ligatures">module io.avaje.config {</span></p>
<p style="margin:0px 0px 0px 28.9px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(128,0,128);min-height:14px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></p>
<p style="margin:0px 0px 0px 43.3px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(128,0,128)"><span style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">  </span>...</span></p>
<p style="margin:0px 0px 0px 43.3px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(128,0,128)"><span style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">  </span>requires static io.avaje.inject;</span></p>
<p style="margin:0px 0px 0px 43.3px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(128,0,128)"><span style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">  </span>...</span></p>
<p style="margin:0px 0px 0px 43.3px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(128,0,128)"><span style="font-variant-ligatures:no-common-ligatures"><span class="gmail-Apple-converted-space">  </span>provides io.avaje.inject.spi.PropertyRequiresPlugin with io.avaje.config.InjectPropertiesPlugin;</span></p>
<p style="margin:0px 0px 0px 28.9px;font-stretch:normal;font-size:12px;line-height:normal;font-family:Menlo;font-size-adjust:none;font-kerning:auto;font-variant-alternates:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-east-asian:normal;font-feature-settings:normal;color:rgb(128,0,128)"><span style="font-variant-ligatures:no-common-ligatures">}</span></p></div><div><br></div><div><br></div><div>When a module is run with module-path without the io.avaje.inject module then the error above occurs at runtime when the module is run using Java 20 (build 20+36-2344).</div><div><br></div><div>So reading <a href="https://docs.oracle.com/javase/9/docs/api/java/lang/module/package-summary.html">https://docs.oracle.com/javase/9/docs/api/java/lang/module/package-summary.html</a></div><div><br></div><div>We see: </div><div><p style="color:rgb(0,0,0)"><i>If any of the following conditions occur in the readability graph, then resolution fails<span style="color:rgb(34,34,34)"> </span></i></p><p style="color:rgb(0,0,0)"><i><span style="color:rgb(34,34,34)">- </span></i><span style="color:rgb(71,71,71);font-family:"DejaVu Serif",Georgia,"Times New Roman",Times,serif;font-size:14px"><i>A module M declares that it 'uses p.S' or 'provides p.S with ...' but package p is neither in module M nor exported to M by any module that M "reads"</i></span></p><p><font color="#474747" face="arial, sans-serif"><span style="font-size:14px">So requires <b><i>static</i></b> io.avaje.inject means it does not "read" io.avaje.inject. To me that suggests we are effectively unable to use requires <b><i>static</i></b> for a provides type (it will compile successfully but we will observe runtime errors if the optional module is indeed not in the module-path). </span></font></p><p><font color="#474747" face="arial, sans-serif"><span style="font-size:14px">Have I missed something obvious? Is there any way to use a requires static with the provides type/package to provide a service that can optionally be used (based on if the module that exports the provides type is in the module path)? This works fine with classpath obviously.</span></font></p><p><font color="#474747" face="arial, sans-serif"><span style="font-size:14px"><br></span></font></p><p><font color="#474747" face="arial, sans-serif"><span style="font-size:14px">Thanks, Rob.</span></font></p></div></div>