@@ -148,14 +148,31 @@ private Provider<String> mapByPrefix(Provider<String> moduleName) {
148148 .filter (e -> moduleName .get ().startsWith (e .getKey ())).findFirst ();
149149 if (prefixToGroup .isPresent ()) {
150150 String group = prefixToGroup .get ().getValue ();
151- String artifact = moduleName .get ().substring (prefixToGroup .get ().getKey ().length ());
151+ String artifact = toProjectName ( moduleName .get ().substring (prefixToGroup .get ().getKey ().length () ));
152152 return group + ":" + artifact ;
153153 }
154154 return null ;
155155 }
156156 );
157157 }
158158
159+ private String toProjectName (String moduleNameSuffix ) {
160+ List <String > allProjectNames = getProject ().getRootProject ().getSubprojects ().stream ().map (Project ::getName ).collect (Collectors .toList ());
161+
162+ Optional <String > perfectMatch = allProjectNames .stream ().filter (p -> p .replace ("-" , "." ).equals (moduleNameSuffix )).findFirst ();
163+ Optional <String > existingProjectName = allProjectNames .stream ().filter (p -> moduleNameSuffix != null && moduleNameSuffix .startsWith (p .replace ("-" , "." ) + "." ))
164+ .max (Comparator .comparingInt (String ::length ));
165+
166+ if (perfectMatch .isPresent ()) {
167+ return perfectMatch .get ();
168+ } else if (existingProjectName .isPresent ()) {
169+ String capabilityClassifier = moduleNameSuffix .substring (existingProjectName .get ().length () + 1 ).replace ("." , "-" );
170+ return existingProjectName .get () + "|" + capabilityClassifier ; // no exact match (assume last segment is capability)
171+ }
172+
173+ return moduleNameSuffix ;
174+ }
175+
159176 public Provider <Dependency > create (String moduleName , SourceSet sourceSetWithModuleInfo ) {
160177 return getProviders ().provider (() -> {
161178 Map <String , String > allProjectNamesAndGroups = getProject ().getRootProject ().getSubprojects ().stream ().collect (
0 commit comments