20
20
import org .gradle .api .artifacts .Configuration ;
21
21
import org .gradle .api .artifacts .ConfigurationContainer ;
22
22
import org .gradle .api .artifacts .Dependency ;
23
+ import org .gradle .api .artifacts .ExternalDependency ;
23
24
import org .gradle .api .artifacts .ModuleDependency ;
24
25
import org .gradle .api .artifacts .ProjectDependency ;
25
26
import org .gradle .api .artifacts .VersionCatalog ;
63
64
import java .util .stream .Collectors ;
64
65
65
66
import static java .util .Optional .empty ;
67
+ import static org .gradlex .javamodule .dependencies .internal .utils .DependencyDeclarationsUtil .copyVersionConstraint ;
66
68
import static org .gradlex .javamodule .dependencies .internal .utils .ModuleInfo .Directive .REQUIRES_RUNTIME ;
67
69
68
70
/**
@@ -280,7 +282,7 @@ private Provider<Dependency> createWithGuessing(String moduleName, SourceSet sou
280
282
private @ Nullable ModuleDependency createExternalDependency (String moduleName ) {
281
283
Provider <String > coordinates = getModuleNameToGA ().getting (moduleName ).orElse (mapByPrefix (getProviders ().provider (() -> moduleName )));
282
284
if (coordinates .isPresent ()) {
283
- Map < String , Object > component ;
285
+ ExternalDependency component ;
284
286
String capability ;
285
287
if (coordinates .get ().contains ("|" )) {
286
288
String [] split = coordinates .get ().split ("\\ |" );
@@ -344,7 +346,7 @@ public Provider<String> gav(Provider<String> moduleName, Provider<String> versio
344
346
* @return Dependency notation
345
347
*/
346
348
@ SuppressWarnings ("unused" )
347
- public Provider <Map < String , Object > > gav (String moduleName ) {
349
+ public Provider <ExternalDependency > gav (String moduleName ) {
348
350
return ga (moduleName ).map (ga -> findGav (ga , moduleName ));
349
351
}
350
352
@@ -358,24 +360,19 @@ public Provider<Map<String, Object>> gav(String moduleName) {
358
360
* @return Dependency notation
359
361
*/
360
362
@ SuppressWarnings ("unused" )
361
- public Provider <Map < String , Object > > gav (Provider <String > moduleName ) {
363
+ public Provider <ExternalDependency > gav (Provider <String > moduleName ) {
362
364
return ga (moduleName ).map (ga -> findGav (ga , moduleName .get ()));
363
365
}
364
366
365
- private Map <String , Object > findGav (String ga , String moduleName ) {
366
- VersionCatalog catalog = versionCatalogs == null ? null : versionCatalogs .find (getVersionCatalogName ().get ()).orElse (null );
367
- Optional <VersionConstraint > version = catalog == null ? empty () : catalog .findVersion (moduleName .replace ('_' , '.' ));
368
- Map <String , Object > gav = new HashMap <>();
369
- String [] gaSplit = ga .split (":" );
370
- if (gaSplit .length < 2 ) {
371
- throw new RuntimeException ("Invalid mapping: " + moduleName + "=" + ga );
372
- }
373
- gav .put (GAV .GROUP , gaSplit [0 ]);
374
- gav .put (GAV .ARTIFACT , gaSplit [1 ]);
375
- version .ifPresent (versionConstraint -> gav .put (GAV .VERSION , versionConstraint ));
376
- return gav ;
367
+ private ExternalDependency findGav (String ga , String moduleName ) {
368
+ Optional <VersionCatalog > catalog = versionCatalogs == null ? empty () : versionCatalogs .find (getVersionCatalogName ().get ());
369
+ Optional <VersionConstraint > version = catalog .flatMap (versionCatalog -> versionCatalog .findVersion (moduleName .replace ('_' , '.' )));
370
+ ExternalDependency dependency = (ExternalDependency ) getDependencies ().create (ga );
371
+ version .ifPresent (versionConstraint -> dependency .version (copy -> copyVersionConstraint (versionConstraint , copy )));
372
+ return dependency ;
377
373
}
378
374
375
+
379
376
/**
380
377
* Finds the Module Name for given coordinates
381
378
*
0 commit comments