in src/main/java/org/apache/maven/plugins/assembly/archive/phase/ModuleSetAssemblyPhase.java [210:300]
void addModuleBinaries(
final Assembly assembly,
ModuleSet moduleSet,
final ModuleBinaries binaries,
final Set<MavenProject> projects,
final Archiver archiver,
final AssemblerConfigurationSource configSource)
throws ArchiveCreationException, AssemblyFormattingException, InvalidAssemblerConfigurationException,
DependencyResolutionException {
if (binaries == null) {
return;
}
final Set<MavenProject> moduleProjects = new LinkedHashSet<>();
MavenProjects.select(projects, "pom", log(LOGGER), addTo(moduleProjects));
final String classifier = binaries.getAttachmentClassifier();
final Map<MavenProject, Artifact> chosenModuleArtifacts = new HashMap<>();
for (final MavenProject project : moduleProjects) {
Artifact artifact;
if (classifier == null) {
LOGGER.debug("Processing binary artifact for module project: " + project.getId());
artifact = project.getArtifact();
} else {
LOGGER.debug("Processing binary attachment: " + classifier + " for module project: " + project.getId());
artifact = MavenProjects.findArtifactByClassifier(project, classifier);
if (artifact == null) {
throw new InvalidAssemblerConfigurationException(
"Cannot find attachment with classifier: " + classifier + " in module project: "
+ project.getId() + ". Please exclude this module from the module-set.");
}
}
chosenModuleArtifacts.put(project, artifact);
addModuleArtifact(artifact, project, archiver, configSource, binaries);
}
final List<DependencySet> depSets = getDependencySets(binaries);
if (depSets != null) {
Map<DependencySet, Set<Artifact>> dependencySetSetMap =
dependencyResolver.resolveDependencySets(assembly, moduleSet, configSource, depSets);
for (final DependencySet ds : depSets) {
// NOTE: Disabling useProjectArtifact flag, since module artifact has already been handled!
ds.setUseProjectArtifact(false);
}
// TODO: The following should be moved into a shared component, cause this
// test is the same as in maven-enforce rules ReactorModuleConvergence.
List<MavenProject> validateModuleVersions = validateModuleVersions(moduleProjects);
if (!validateModuleVersions.isEmpty()) {
StringBuilder sb =
new StringBuilder().append("The current modules seemed to be having different versions.");
sb.append(LINE_SEPARATOR);
for (MavenProject mavenProject : validateModuleVersions) {
sb.append(" --> ");
sb.append(mavenProject.getId());
sb.append(LINE_SEPARATOR);
}
LOGGER.warn(sb.toString());
}
for (final MavenProject moduleProject : moduleProjects) {
LOGGER.debug("Processing binary dependencies for module project: " + moduleProject.getId());
for (Map.Entry<DependencySet, Set<Artifact>> dependencySetSetEntry : dependencySetSetMap.entrySet()) {
final AddDependencySetsTask task = new AddDependencySetsTask(
Collections.singletonList(dependencySetSetEntry.getKey()),
dependencySetSetEntry.getValue(),
moduleProject,
projectBuilder);
task.setModuleProject(moduleProject);
task.setModuleArtifact(chosenModuleArtifacts.get(moduleProject));
task.setDefaultOutputDirectory(binaries.getOutputDirectory());
task.setDefaultOutputFileNameMapping(binaries.getOutputFileNameMapping());
task.execute(archiver, configSource);
}
}
}
}