Prioritize the use of dependModules when both dependModules and main are satisfied

Closes gh-24
This commit is contained in:
Weix Sun 2022-12-17 01:53:11 +08:00
parent 5ed1758a1c
commit c606401f88

View File

@ -153,22 +153,22 @@ public class MulitModuleMavenBuildProjectContributor extends MavenBuildProjectCo
}
} else {
List<String> dependModules
= module.getDependModules() == null ? Collections.emptyList() : module.getDependModules().stream()
.distinct().map(this::toFinalArtifactId).toList();
if (module.isMain()) {
// main module depend all other submodules
List<Module> subModules = arch.getSubModules();
for (Module subModule : subModules) {
if (subModule == module) {
continue;
}
addModuleDependency(toFinalArtifactId(subModule.getName()));
if (dependModules.isEmpty()) {
// main module depend all other submodules
List<String> subModules = arch.getSubModules().stream().distinct()
.filter(subModule -> subModule != module)
.map(subModule -> toFinalArtifactId(subModule.getName()))
.toList();
addModuleDependencies(subModules);
} else {
addModuleDependencies(dependModules);
}
} else {
List<String> dependModules
= module.getDependModules() == null ? Collections.emptyList() : module.getDependModules().stream()
.distinct().map(dependModule -> toFinalArtifactId(dependModule)).collect(Collectors.toUnmodifiableList());
for (String dependModule : dependModules) {
addModuleDependency(dependModule);
}
addModuleDependencies(dependModules);
}
// remove all dependencymanager
@ -206,6 +206,12 @@ public class MulitModuleMavenBuildProjectContributor extends MavenBuildProjectCo
}
}
private void addModuleDependencies(List<String> dependModules) {
for (String dependModule : dependModules) {
addModuleDependency(dependModule);
}
}
private void addModuleDependency(String subModule) {
this.build.dependencies().add(subModule, Dependency.withCoordinates(description.getGroupId(), subModule));
}