use of org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependencyConstraint in project gradle by gradle.
the class DefaultMavenPublication method populateFromComponent.
private void populateFromComponent() {
if (populated) {
return;
}
populated = true;
if (component == null) {
return;
}
MavenPublicationErrorChecker.checkForUnpublishableAttributes(component, documentationRegistry);
PublicationWarningsCollector publicationWarningsCollector = new PublicationWarningsCollector(LOG, UNSUPPORTED_FEATURE, INCOMPATIBLE_FEATURE, PUBLICATION_WARNING_FOOTER, "suppressPomMetadataWarningsFor");
Set<ArtifactKey> seenArtifacts = Sets.newHashSet();
Set<PublishedDependency> seenDependencies = Sets.newHashSet();
Set<DependencyConstraint> seenConstraints = Sets.newHashSet();
for (UsageContext usageContext : getSortedUsageContexts()) {
// TODO Need a smarter way to map usage to artifact classifier
for (PublishArtifact publishArtifact : usageContext.getArtifacts()) {
ArtifactKey key = new ArtifactKey(publishArtifact.getFile(), publishArtifact.getClassifier(), publishArtifact.getExtension());
if (!artifactsOverridden && seenArtifacts.add(key)) {
artifact(publishArtifact);
}
}
Set<ExcludeRule> globalExcludes = usageContext.getGlobalExcludes();
publicationWarningsCollector.newContext(usageContext.getName());
Set<MavenDependencyInternal> dependencies = dependenciesFor(usageContext);
for (ModuleDependency dependency : usageContext.getDependencies()) {
if (seenDependencies.add(PublishedDependency.of(dependency))) {
if (isDependencyWithDefaultArtifact(dependency) && dependencyMatchesProject(dependency)) {
// We skip all self referencing dependency declarations, unless they have custom artifact information
continue;
}
if (platformSupport.isTargetingPlatform(dependency)) {
if (dependency instanceof ProjectDependency) {
addImportDependencyConstraint((ProjectDependency) dependency);
} else {
if (!versionMappingInUse && isVersionMavenIncompatible(dependency.getVersion())) {
publicationWarningsCollector.addIncompatible(String.format("%s:%s:%s declared with a Maven incompatible version notation", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
}
addImportDependencyConstraint(dependency);
}
} else {
if (!dependency.getAttributes().isEmpty()) {
publicationWarningsCollector.addUnsupported(String.format("%s:%s:%s declared with Gradle attributes", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
}
if (dependency instanceof ProjectDependency) {
addProjectDependency((ProjectDependency) dependency, globalExcludes, dependencies);
} else {
if (!versionMappingInUse && isVersionMavenIncompatible(dependency.getVersion())) {
publicationWarningsCollector.addIncompatible(String.format("%s:%s:%s declared with a Maven incompatible version notation", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
}
addModuleDependency(dependency, globalExcludes, dependencies);
}
}
}
}
Set<MavenDependency> dependencyConstraints = dependencyConstraintsFor(usageContext);
for (DependencyConstraint dependency : usageContext.getDependencyConstraints()) {
if (seenConstraints.add(dependency)) {
if (dependency instanceof DefaultProjectDependencyConstraint) {
addDependencyConstraint((DefaultProjectDependencyConstraint) dependency, dependencyConstraints);
} else if (dependency.getVersion() != null) {
if (!versionMappingInUse && isVersionMavenIncompatible(dependency.getVersion())) {
publicationWarningsCollector.addIncompatible(String.format("constraint %s:%s:%s declared with a Maven incompatible version notation", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
}
addDependencyConstraint(dependency, dependencyConstraints);
}
}
}
if (!usageContext.getCapabilities().isEmpty()) {
for (Capability capability : usageContext.getCapabilities()) {
if (isNotDefaultCapability(capability)) {
publicationWarningsCollector.addVariantUnsupported(String.format("Declares capability %s:%s:%s which cannot be mapped to Maven", capability.getGroup(), capability.getName(), capability.getVersion()));
}
}
}
}
if (!silenceAllPublicationWarnings) {
publicationWarningsCollector.complete(getDisplayName() + " pom metadata", silencedVariants);
}
}
use of org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependencyConstraint in project gradle by gradle.
the class ModuleMetadataSpecBuilder method dependencyConstraintFor.
private ModuleMetadataSpec.DependencyConstraint dependencyConstraintFor(DependencyConstraint dependencyConstraint, VariantVersionMappingStrategyInternal variantVersionMappingStrategy, String variant) {
String group;
String module;
String resolvedVersion = null;
String projectPath = null;
if (dependencyConstraint instanceof DefaultProjectDependencyConstraint) {
DefaultProjectDependencyConstraint dependency = (DefaultProjectDependencyConstraint) dependencyConstraint;
ProjectDependency projectDependency = dependency.getProjectDependency();
ModuleVersionIdentifier identifier = moduleIdentifierFor(projectDependency);
group = identifier.getGroup();
module = identifier.getName();
projectPath = projectDependency.getDependencyProject().getPath();
resolvedVersion = identifier.getVersion();
} else {
group = dependencyConstraint.getGroup();
module = dependencyConstraint.getName();
}
ModuleVersionIdentifier resolvedVersionId = variantVersionMappingStrategy != null ? variantVersionMappingStrategy.maybeResolveVersion(group, module, projectPath) : null;
String effectiveGroup = resolvedVersionId != null ? resolvedVersionId.getGroup() : group;
String effectiveModule = resolvedVersionId != null ? resolvedVersionId.getName() : module;
String effectiveVersion = resolvedVersionId != null ? resolvedVersionId.getVersion() : resolvedVersion;
return new ModuleMetadataSpec.DependencyConstraint(effectiveGroup, effectiveModule, versionFor(DefaultImmutableVersionConstraint.of(dependencyConstraint.getVersionConstraint()), effectiveVersion), dependencyAttributesFor(variant, dependencyConstraint.getGroup(), dependencyConstraint.getName(), dependencyConstraint.getAttributes()), isNotEmpty(dependencyConstraint.getReason()) ? dependencyConstraint.getReason() : null);
}
Aggregations