@@ -494,13 +494,31 @@ private byte[] readAllBytes(InputStream inputStream) throws IOException {
494494
495495 private String gaToModuleName (String ga ) {
496496 ModuleSpec moduleSpec = getParameters ().getModuleSpecs ().get ().get (ga );
497- if (moduleSpec == null ) {
498- throw new RuntimeException ("[requires directives from metadata] " +
499- "The module name of the following component is not known: " + ga +
500- "\n - If it is already a module, make the module name known using 'knownModule(\" " + ga + "\" , \" <module name>\" )'" +
501- "\n - If it is not a module, patch it using 'module()' or 'automaticModule()'" );
497+ if (moduleSpec != null ) {
498+ return moduleSpec .getModuleName ();
502499 }
503- return moduleSpec .getModuleName ();
500+ String moduleNameFromSharedMapping = moduleNameFromSharedMapping (ga );
501+ if (moduleNameFromSharedMapping != null ) {
502+ return moduleNameFromSharedMapping ;
503+ }
504+
505+ throw new RuntimeException ("[requires directives from metadata] " +
506+ "The module name of the following component is not known: " + ga +
507+ "\n - If it is already a module, make the module name known using 'knownModule(\" " + ga + "\" , \" <module name>\" )'" +
508+ "\n - If it is not a module, patch it using 'module()' or 'automaticModule()'" );
509+ }
510+
511+ @ Nullable
512+ private String moduleNameFromSharedMapping (String ga ) {
513+ try {
514+ Class <?> sharedMappings = Class .forName ("org.gradlex.javamodule.dependencies.SharedMappings" );
515+ @ SuppressWarnings ("unchecked" )
516+ Map <String , String > mappings = (Map <String , String >) sharedMappings .getDeclaredField ("mappings" ).get (null );
517+ Optional <String > found = mappings .entrySet ().stream ().filter (
518+ e -> e .getValue ().equals (ga )).map (Map .Entry ::getKey ).findFirst ();
519+ return found .orElse (null );
520+ } catch (ReflectiveOperationException ignored ) { }
521+ return null ;
504522 }
505523
506524 private static boolean isModuleInfoClass (String jarEntryName ) {
0 commit comments