use of org.gradle.api.capabilities.Capability 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.capabilities.Capability in project gradle by gradle.
the class JavaPlatformPlugin method createConfigurations.
private void createConfigurations(Project project) {
ConfigurationContainer configurations = project.getConfigurations();
Capability enforcedCapability = new DefaultShadowedCapability(new ProjectDerivedCapability(project), "-derived-enforced-platform");
Configuration api = configurations.create(API_CONFIGURATION_NAME, AS_BUCKET);
Configuration apiElements = createConsumableApi(project, configurations, api, API_ELEMENTS_CONFIGURATION_NAME, Category.REGULAR_PLATFORM);
Configuration enforcedApiElements = createConsumableApi(project, configurations, api, ENFORCED_API_ELEMENTS_CONFIGURATION_NAME, Category.ENFORCED_PLATFORM);
enforcedApiElements.getOutgoing().capability(enforcedCapability);
Configuration runtime = project.getConfigurations().create(RUNTIME_CONFIGURATION_NAME, AS_BUCKET);
runtime.extendsFrom(api);
Configuration runtimeElements = createConsumableRuntime(project, runtime, RUNTIME_ELEMENTS_CONFIGURATION_NAME, Category.REGULAR_PLATFORM);
Configuration enforcedRuntimeElements = createConsumableRuntime(project, runtime, ENFORCED_RUNTIME_ELEMENTS_CONFIGURATION_NAME, Category.ENFORCED_PLATFORM);
enforcedRuntimeElements.getOutgoing().capability(enforcedCapability);
Configuration classpath = configurations.create(CLASSPATH_CONFIGURATION_NAME, AS_RESOLVABLE_CONFIGURATION);
classpath.extendsFrom(runtimeElements);
declareConfigurationUsage(project.getObjects(), classpath, Usage.JAVA_RUNTIME, LibraryElements.JAR);
createSoftwareComponent(project, apiElements, runtimeElements);
}
use of org.gradle.api.capabilities.Capability in project gradle by gradle.
the class ModuleComponentSelectorSerializer method read.
@Override
public ModuleComponentSelector read(Decoder decoder) throws IOException {
String group = decoder.readString();
String name = decoder.readString();
VersionConstraint versionConstraint = readVersionConstraint(decoder);
ImmutableAttributes attributes = readAttributes(decoder);
List<Capability> capabilities = readCapabilities(decoder);
return newSelector(DefaultModuleIdentifier.newId(group, name), versionConstraint, attributes, capabilities);
}
use of org.gradle.api.capabilities.Capability in project gradle by gradle.
the class ModuleComponentSelectorSerializer method readCapabilities.
private List<Capability> readCapabilities(Decoder decoder) throws IOException {
int size = decoder.readSmallInt();
if (size == 0) {
return Collections.emptyList();
}
ImmutableList.Builder<Capability> builder = ImmutableList.builderWithExpectedSize(size);
for (int i = 0; i < size; i++) {
builder.add(new ImmutableCapability(decoder.readString(), decoder.readString(), decoder.readNullableString()));
}
return builder.build();
}
use of org.gradle.api.capabilities.Capability in project gradle by gradle.
the class NodeState method getResolvedVariant.
public ResolvedVariantResult getResolvedVariant() {
if (cachedVariantResult != null) {
return cachedVariantResult;
}
DisplayName name = Describables.of(metaData.getName());
List<? extends Capability> capabilities = metaData.getCapabilities().getCapabilities();
AttributeContainer attributes = desugar(metaData.getAttributes());
List<Capability> resolvedVariantCapabilities = capabilities.isEmpty() ? Collections.singletonList(component.getImplicitCapability()) : ImmutableList.copyOf(capabilities);
cachedVariantResult = new DefaultResolvedVariantResult(component.getComponentId(), name, attributes, resolvedVariantCapabilities, findExternalVariant());
return cachedVariantResult;
}
Aggregations