use of org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier in project gradle by gradle.
the class ProjectDependencyPublicationResolver method resolve.
public ModuleVersionIdentifier resolve(ProjectDependency dependency) {
Project dependencyProject = dependency.getDependencyProject();
((ProjectInternal) dependencyProject).evaluate();
PublishingExtension publishing = dependencyProject.getExtensions().findByType(PublishingExtension.class);
if (publishing == null || publishing.getPublications().withType(PublicationInternal.class).isEmpty()) {
// Project does not apply publishing (or has no publications): simply use the project name in place of the dependency name
return new DefaultModuleVersionIdentifier(dependency.getGroup(), dependencyProject.getName(), dependency.getVersion());
}
// See if all publications have the same identifier
Set<? extends PublicationInternal> publications = publishing.getPublications().withType(PublicationInternal.class);
Iterator<? extends PublicationInternal> iterator = publications.iterator();
ModuleVersionIdentifier candidate = iterator.next().getCoordinates();
while (iterator.hasNext()) {
ModuleVersionIdentifier alternative = iterator.next().getCoordinates();
if (!candidate.equals(alternative)) {
throw new UnsupportedOperationException("Publishing is not yet able to resolve a dependency on a project with multiple different publications.");
}
}
return candidate;
}
use of org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier in project gradle by gradle.
the class DefaultProjectDependencyPublicationResolver method resolve.
@Override
public <T> T resolve(Class<T> coordsType, ProjectDependency dependency) {
// Could probably apply some caching and some immutable types
ProjectInternal dependencyProject = (ProjectInternal) dependency.getDependencyProject();
// Ensure target project is configured
projectConfigurer.configureFully(dependencyProject);
List<ProjectPublication> publications = new ArrayList<ProjectPublication>();
for (ProjectPublication publication : publicationRegistry.getPublications(dependencyProject.getPath())) {
if (!publication.isLegacy() && publication.getCoordinates(coordsType) != null) {
publications.add(publication);
}
}
if (publications.isEmpty()) {
// Project has no publications: simply use the project name in place of the dependency name
if (coordsType.isAssignableFrom(ModuleVersionIdentifier.class)) {
return coordsType.cast(new DefaultModuleVersionIdentifier(dependency.getGroup(), dependencyProject.getName(), dependency.getVersion()));
}
throw new UnsupportedOperationException(String.format("Could not find any publications of type %s in %s.", coordsType.getSimpleName(), dependencyProject.getDisplayName()));
}
// Select all entry points. An entry point is a publication that does not contain a component whose parent is also published
Set<SoftwareComponent> ignored = new HashSet<SoftwareComponent>();
for (ProjectPublication publication : publications) {
if (publication.getComponent() != null && publication.getComponent() instanceof ComponentWithVariants) {
ComponentWithVariants parent = (ComponentWithVariants) publication.getComponent();
ignored.addAll(parent.getVariants());
}
}
Set<ProjectPublication> topLevel = new LinkedHashSet<ProjectPublication>();
for (ProjectPublication publication : publications) {
if (!publication.isAlias() && (publication.getComponent() == null || !ignored.contains(publication.getComponent()))) {
topLevel.add(publication);
}
}
// See if all entry points have the same identifier
Iterator<ProjectPublication> iterator = topLevel.iterator();
T candidate = iterator.next().getCoordinates(coordsType);
while (iterator.hasNext()) {
T alternative = iterator.next().getCoordinates(coordsType);
if (!candidate.equals(alternative)) {
TreeFormatter formatter = new TreeFormatter();
formatter.node("Publishing is not able to resolve a dependency on a project with multiple publications that have different coordinates.");
formatter.node("Found the following publications in " + dependencyProject.getDisplayName());
formatter.startChildren();
for (ProjectPublication publication : topLevel) {
formatter.node(publication.getDisplayName().getCapitalizedDisplayName() + " with coordinates " + publication.getCoordinates(coordsType));
}
formatter.endChildren();
throw new UnsupportedOperationException(formatter.toString());
}
}
return candidate;
}
Aggregations