Search in sources :

Example 1 with ConfigurationNotConsumableException

use of org.gradle.internal.exceptions.ConfigurationNotConsumableException in project gradle by gradle.

the class LocalComponentDependencyMetadata method selectConfigurations.

@Override
public Set<ConfigurationMetadata> selectConfigurations(ComponentResolveMetadata fromComponent, ConfigurationMetadata fromConfiguration, ComponentResolveMetadata targetComponent, AttributesSchema attributesSchema) {
    AttributeContainerInternal fromConfigurationAttributes = fromConfiguration.getAttributes();
    boolean consumerHasAttributes = !fromConfigurationAttributes.isEmpty();
    boolean useConfigurationAttributes = dependencyConfiguration == null && consumerHasAttributes;
    AttributesSchema producerAttributeSchema = targetComponent.getAttributesSchema() == null ? attributesSchema : targetComponent.getAttributesSchema();
    if (useConfigurationAttributes) {
        List<? extends ConfigurationMetadata> consumableConfigurations = targetComponent.getConsumableConfigurationsHavingAttributes();
        List<? extends ConfigurationMetadata> matches = ((AttributesSchemaInternal) attributesSchema).getMatches(producerAttributeSchema, consumableConfigurations, fromConfigurationAttributes);
        if (matches.size() == 1) {
            return ImmutableSet.of(ClientAttributesPreservingConfigurationMetadata.wrapIfLocal(matches.get(0), fromConfigurationAttributes));
        } else if (!matches.isEmpty()) {
            throw new AmbiguousConfigurationSelectionException(fromConfigurationAttributes, attributesSchema, matches, targetComponent);
        }
    }
    String targetConfiguration = GUtil.elvis(dependencyConfiguration, Dependency.DEFAULT_CONFIGURATION);
    ConfigurationMetadata toConfiguration = targetComponent.getConfiguration(targetConfiguration);
    if (toConfiguration == null) {
        throw new ConfigurationNotFoundException(fromComponent.getComponentId(), moduleConfiguration, targetConfiguration, targetComponent.getComponentId());
    }
    if (!toConfiguration.isCanBeConsumed()) {
        if (dependencyConfiguration == null) {
            // this was a fallback to `default`, and `default` is not consumable
            Set<String> configurationNames = Sets.newTreeSet();
            configurationNames.addAll(targetComponent.getConfigurationNames());
            throw new NoMatchingConfigurationSelectionException(fromConfigurationAttributes, attributesSchema, targetComponent, Lists.newArrayList(configurationNames));
        }
        // explicit configuration selection
        throw new ConfigurationNotConsumableException(targetComponent.toString(), toConfiguration.getName());
    }
    ConfigurationMetadata delegate = toConfiguration;
    if (consumerHasAttributes) {
        if (!delegate.getAttributes().isEmpty()) {
            // need to validate that the selected configuration still matches the consumer attributes
            List<ConfigurationMetadata> matches = ((AttributesSchemaInternal) attributesSchema).getMatches(producerAttributeSchema, Collections.singletonList(delegate), fromConfigurationAttributes);
            if (matches.isEmpty()) {
                throw new IncompatibleConfigurationSelectionException(fromConfigurationAttributes, attributesSchema, targetComponent, targetConfiguration);
            }
        }
    }
    if (useConfigurationAttributes) {
        delegate = ClientAttributesPreservingConfigurationMetadata.wrapIfLocal(delegate, fromConfigurationAttributes);
    }
    return ImmutableSet.of(delegate);
}
Also used : ConfigurationNotConsumableException(org.gradle.internal.exceptions.ConfigurationNotConsumableException) AmbiguousConfigurationSelectionException(org.gradle.internal.component.AmbiguousConfigurationSelectionException) AttributesSchema(org.gradle.api.attributes.AttributesSchema) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal) NoMatchingConfigurationSelectionException(org.gradle.internal.component.NoMatchingConfigurationSelectionException) AttributeContainerInternal(org.gradle.api.internal.attributes.AttributeContainerInternal) LocalConfigurationMetadata(org.gradle.internal.component.local.model.LocalConfigurationMetadata) IncompatibleConfigurationSelectionException(org.gradle.internal.component.IncompatibleConfigurationSelectionException)

Example 2 with ConfigurationNotConsumableException

use of org.gradle.internal.exceptions.ConfigurationNotConsumableException in project gradle by gradle.

the class LocalComponentDependencyMetadata method selectConfigurations.

/**
 * Choose a single target configuration based on: a) the consumer attributes, b) the target configuration name and c) the target component
 *
 * Use attribute matching to choose a single variant when:
 *   - The target configuration name is not specified AND
 *   - Either: we have consumer attributes OR the target component has variants.
 *
 * Otherwise, revert to legacy selection of target configuration.
 *
 * @return A List containing a single `ConfigurationMetadata` representing the target variant.
 */
@Override
public List<ConfigurationMetadata> selectConfigurations(ImmutableAttributes consumerAttributes, ComponentResolveMetadata targetComponent, AttributesSchemaInternal consumerSchema) {
    boolean consumerHasAttributes = !consumerAttributes.isEmpty();
    List<? extends ConfigurationMetadata> targetVariants = targetComponent.getVariantsForGraphTraversal();
    boolean useConfigurationAttributes = dependencyConfiguration == null && (consumerHasAttributes || !targetVariants.isEmpty());
    if (useConfigurationAttributes) {
        return ImmutableList.of(AttributeConfigurationSelector.selectConfigurationUsingAttributeMatching(consumerAttributes, targetComponent, consumerSchema));
    }
    String targetConfiguration = GUtil.elvis(dependencyConfiguration, Dependency.DEFAULT_CONFIGURATION);
    ConfigurationMetadata toConfiguration = targetComponent.getConfiguration(targetConfiguration);
    if (toConfiguration == null) {
        throw new ConfigurationNotFoundException(componentId, moduleConfiguration, targetConfiguration, targetComponent.getId());
    }
    if (!toConfiguration.isCanBeConsumed()) {
        throw new ConfigurationNotConsumableException(targetComponent.toString(), toConfiguration.getName());
    }
    if (consumerHasAttributes && !toConfiguration.getAttributes().isEmpty()) {
        // need to validate that the selected configuration still matches the consumer attributes
        // Note that this validation only occurs when `dependencyConfiguration != null` (otherwise we would select with attribute matching)
        AttributesSchemaInternal producerAttributeSchema = targetComponent.getAttributesSchema();
        if (!consumerSchema.withProducer(producerAttributeSchema).isMatching(toConfiguration.getAttributes(), consumerAttributes)) {
            throw new IncompatibleConfigurationSelectionException(consumerAttributes, consumerSchema.withProducer(producerAttributeSchema), targetComponent, targetConfiguration);
        }
    }
    return ImmutableList.of(toConfiguration);
}
Also used : ConfigurationNotConsumableException(org.gradle.internal.exceptions.ConfigurationNotConsumableException) AttributesSchemaInternal(org.gradle.api.internal.attributes.AttributesSchemaInternal) IncompatibleConfigurationSelectionException(org.gradle.internal.component.IncompatibleConfigurationSelectionException)

Example 3 with ConfigurationNotConsumableException

use of org.gradle.internal.exceptions.ConfigurationNotConsumableException in project gradle by gradle.

the class DefaultProjectDependency method findProjectConfiguration.

@Override
public Configuration findProjectConfiguration() {
    ConfigurationContainer dependencyConfigurations = getDependencyProject().getConfigurations();
    String declaredConfiguration = getTargetConfiguration();
    Configuration selectedConfiguration = dependencyConfigurations.getByName(GUtil.elvis(declaredConfiguration, Dependency.DEFAULT_CONFIGURATION));
    if (!selectedConfiguration.isCanBeConsumed()) {
        throw new ConfigurationNotConsumableException(dependencyProject.getDisplayName(), selectedConfiguration.getName());
    }
    warnIfConfigurationIsDeprecated((DeprecatableConfiguration) selectedConfiguration);
    return selectedConfiguration;
}
Also used : ConfigurationNotConsumableException(org.gradle.internal.exceptions.ConfigurationNotConsumableException) Configuration(org.gradle.api.artifacts.Configuration) DeprecatableConfiguration(org.gradle.internal.deprecation.DeprecatableConfiguration) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer)

Aggregations

ConfigurationNotConsumableException (org.gradle.internal.exceptions.ConfigurationNotConsumableException)3 AttributesSchemaInternal (org.gradle.api.internal.attributes.AttributesSchemaInternal)2 IncompatibleConfigurationSelectionException (org.gradle.internal.component.IncompatibleConfigurationSelectionException)2 Configuration (org.gradle.api.artifacts.Configuration)1 ConfigurationContainer (org.gradle.api.artifacts.ConfigurationContainer)1 AttributesSchema (org.gradle.api.attributes.AttributesSchema)1 AttributeContainerInternal (org.gradle.api.internal.attributes.AttributeContainerInternal)1 AmbiguousConfigurationSelectionException (org.gradle.internal.component.AmbiguousConfigurationSelectionException)1 NoMatchingConfigurationSelectionException (org.gradle.internal.component.NoMatchingConfigurationSelectionException)1 LocalConfigurationMetadata (org.gradle.internal.component.local.model.LocalConfigurationMetadata)1 DeprecatableConfiguration (org.gradle.internal.deprecation.DeprecatableConfiguration)1