5252import java .io .File ;
5353import java .io .IOException ;
5454import java .util .Arrays ;
55+ import java .util .Collection ;
5556import java .util .Collections ;
5657import java .util .Comparator ;
5758import java .util .HashMap ;
@@ -368,12 +369,16 @@ public Provider<String> moduleName(Provider<String> ga) {
368369 });
369370 }
370371
372+ public Configuration versionsFromConsistentResolution (String ... versionsProvidingProjects ) {
373+ return versionsFromConsistentResolution (Arrays .asList (versionsProvidingProjects ));
374+ }
375+
371376 /**
372377 * Use consistent resolution to manage versions consistently through in the main application project(s).
373378 *
374379 * @param versionsProvidingProjects projects which runtime classpaths are the runtime classpaths of the applications/services being built.
375380 */
376- public Configuration versionsFromConsistentResolution (String ... versionsProvidingProjects ) {
381+ public Configuration versionsFromConsistentResolution (Collection < String > versionsProvidingProjects ) {
377382 ObjectFactory objects = getObjects ();
378383 Configuration mainRuntimeClasspath = getConfigurations ().create ("mainRuntimeClasspath" , c -> {
379384 c .setCanBeConsumed (false );
@@ -396,38 +401,48 @@ public Configuration versionsFromConsistentResolution(String... versionsProvidin
396401 }
397402
398403 public Configuration versionsFromPlatformAndConsistentResolution (String platformProject , String ... versionsProvidingProjects ) {
399- boolean platformInJavaProject = Arrays .asList (versionsProvidingProjects ).contains (platformProject );
400-
401- if (getConfigurations ().findByName (INTERNAL ) == null ) {
402- getConfigurations ().create ("internal" , internal -> {
403- internal .setCanBeResolved (false );
404- internal .setCanBeConsumed (false );
405- internal .withDependencies (d -> {
406- Dependency platformDependency = getDependencies ().platform (createDependency (platformProject ));
407- if (platformInJavaProject ) {
408- if (platformProject .startsWith (":" )) {
409- String capability = ((ProjectDependency ) platformDependency ).getDependencyProject ().getGroup () + platformProject + "-platform" ;
410- ((ProjectDependency ) platformDependency ).capabilities (c -> c .requireCapability (capability ));
411- } else if (platformDependency instanceof ModuleDependency ) {
412- String capability = platformProject + "-platform" ;
413- ((ModuleDependency ) platformDependency ).capabilities (c -> c .requireCapability (capability ));
414- }
415- }
416- d .add (platformDependency );
417- });
418- });
419- }
404+ return versionsFromPlatformAndConsistentResolution (platformProject , Arrays .asList (versionsProvidingProjects ));
405+ }
406+
407+ public Configuration versionsFromPlatformAndConsistentResolution (String platformProject , Collection <String > versionsProvidingProjects ) {
408+ boolean platformInJavaProject = versionsProvidingProjects .contains (platformProject );
409+
410+ maybeCreateInternalConfiguration ().withDependencies (d -> {
411+ Dependency platformDependency = getDependencies ().platform (createDependency (platformProject ));
412+ if (platformInJavaProject ) {
413+ if (platformProject .startsWith (":" )) {
414+ String capability = ((ProjectDependency ) platformDependency ).getDependencyProject ().getGroup () + platformProject + "-platform" ;
415+ ((ProjectDependency ) platformDependency ).capabilities (c -> c .requireCapability (capability ));
416+ } else if (platformDependency instanceof ModuleDependency ) {
417+ String capability = platformProject + "-platform" ;
418+ ((ModuleDependency ) platformDependency ).capabilities (c -> c .requireCapability (capability ));
419+ }
420+ }
421+ d .add (platformDependency );
422+ });
420423
421424 getSourceSets ().configureEach (sourceSet -> {
422- Configuration internal = getConfigurations ().getByName (INTERNAL );
423- getConfigurations ().getByName (sourceSet .getRuntimeClasspathConfigurationName ()).extendsFrom (internal );
424- getConfigurations ().getByName (sourceSet .getCompileClasspathConfigurationName ()).extendsFrom (internal );
425- getConfigurations ().getByName (sourceSet .getAnnotationProcessorConfigurationName ()).extendsFrom (internal );
425+ ConfigurationContainer configurations = getConfigurations ();
426+ Configuration internal = configurations .getByName (INTERNAL );
427+ configurations .getByName (sourceSet .getRuntimeClasspathConfigurationName ()).extendsFrom (internal );
428+ configurations .getByName (sourceSet .getCompileClasspathConfigurationName ()).extendsFrom (internal );
429+ configurations .getByName (sourceSet .getAnnotationProcessorConfigurationName ()).extendsFrom (internal );
426430 });
427431
428432 return versionsFromConsistentResolution (versionsProvidingProjects );
429433 }
430434
435+ private Configuration maybeCreateInternalConfiguration () {
436+ Configuration internal = getConfigurations ().findByName (INTERNAL );
437+ if (internal != null ) {
438+ return internal ;
439+ }
440+ return getConfigurations ().create (INTERNAL , i -> {
441+ i .setCanBeResolved (false );
442+ i .setCanBeConsumed (false );
443+ });
444+ }
445+
431446 private Dependency createDependency (String project ) {
432447 boolean isProjectInBuild = project .startsWith (":" );
433448 return getDependencies ().create (isProjectInBuild
0 commit comments