2121import org .gradle .api .Project ;
2222import org .gradle .api .Transformer ;
2323import org .gradle .api .artifacts .Configuration ;
24+ import org .gradle .api .artifacts .ConfigurationContainer ;
2425import org .gradle .api .artifacts .component .ComponentIdentifier ;
2526import org .gradle .api .artifacts .component .ModuleComponentIdentifier ;
27+ import org .gradle .api .artifacts .dsl .DependencyHandler ;
2628import org .gradle .api .artifacts .result .DependencyResult ;
2729import org .gradle .api .artifacts .result .ResolvedArtifactResult ;
2830import org .gradle .api .artifacts .result .ResolvedDependencyResult ;
@@ -104,13 +106,15 @@ private void configureTransform(Project project, ExtraJavaModuleInfoPluginExtens
104106 }
105107
106108 private void registerTransform (String fileExtension , Project project , ExtraJavaModuleInfoPluginExtension extension , Configuration javaModulesMergeJars , Attribute <String > artifactType , Attribute <Boolean > javaModule ) {
109+ DependencyHandler dependencies = project .getDependencies ();
110+ ConfigurationContainer configurations = project .getConfigurations ();
111+ SourceSetContainer sourceSets = project .getExtensions ().getByType (SourceSetContainer .class );
112+
107113 // all Jars have a javaModule=false attribute by default; the transform also recognizes modules and returns them without modification
108- project .getDependencies ().getArtifactTypes ().maybeCreate (fileExtension ).getAttributes ().attribute (javaModule , false );
109- Configuration compileClasspath = project .getConfigurations ().getByName (JavaPlugin .COMPILE_CLASSPATH_CONFIGURATION_NAME );
110- Configuration runtimeClasspath = project .getConfigurations ().getByName (JavaPlugin .RUNTIME_CLASSPATH_CONFIGURATION_NAME );
114+ dependencies .getArtifactTypes ().maybeCreate (fileExtension ).getAttributes ().attribute (javaModule , false );
111115
112116 // register the transform for Jars and "javaModule=false -> javaModule=true"; the plugin extension object fills the input parameter
113- project . getDependencies () .registerTransform (ExtraJavaModuleInfoTransform .class , t -> {
117+ dependencies .registerTransform (ExtraJavaModuleInfoTransform .class , t -> {
114118 t .parameters (p -> {
115119 p .getModuleSpecs ().set (extension .getModuleSpecs ());
116120 p .getFailOnMissingModuleInfo ().set (extension .getFailOnMissingModuleInfo ());
@@ -121,14 +125,16 @@ private void registerTransform(String fileExtension, Project project, ExtraJavaM
121125 p .getMergeJarIds ().set (artifacts .map (new IdExtractor ()));
122126 p .getMergeJars ().set (artifacts .map (new FileExtractor (project .getLayout ())));
123127 p .getCompileClasspathDependencies ().set (project .provider (() ->
124- compileClasspath . getIncoming ().getResolutionResult ().getAllComponents ().stream ().collect (Collectors .toMap (
128+ sourceSets . stream (). flatMap ( s -> configurations . getByName ( s . getCompileClasspathConfigurationName ()). getIncoming ().getResolutionResult ().getAllComponents ().stream () ).collect (Collectors .toMap (
125129 c -> ga (c .getId ()),
126- c -> c .getDependencies ().stream ().map (ExtraJavaModuleInfoPlugin ::ga ).collect (Collectors .toSet ())
130+ c -> c .getDependencies ().stream ().map (ExtraJavaModuleInfoPlugin ::ga ).collect (Collectors .toSet ()),
131+ (dependencies1 , dependencies2 ) -> dependencies1 // There can be duplications which are assumed to be the same
127132 ))));
128133 p .getRuntimeClasspathDependencies ().set (project .provider (() ->
129- runtimeClasspath . getIncoming ().getResolutionResult ().getAllComponents ().stream ().collect (Collectors .toMap (
134+ sourceSets . stream (). flatMap ( s -> configurations . getByName ( s . getRuntimeClasspathConfigurationName ()). getIncoming ().getResolutionResult ().getAllComponents ().stream () ).collect (Collectors .toMap (
130135 c -> ga (c .getId ()),
131- c -> c .getDependencies ().stream ().map (ExtraJavaModuleInfoPlugin ::ga ).collect (Collectors .toSet ())
136+ c -> c .getDependencies ().stream ().map (ExtraJavaModuleInfoPlugin ::ga ).collect (Collectors .toSet ()),
137+ (dependencies1 , dependencies2 ) -> dependencies1 // There can be duplications which are assumed to be the same
132138 ))));
133139 });
134140 t .getFrom ().attribute (artifactType , fileExtension ).attribute (javaModule , false );
0 commit comments