Search in sources :

Example 21 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class ProjectDependencyResolver method resolve.

@Override
public void resolve(DependencyMetadata dependency, VersionSelector acceptor, @Nullable VersionSelector rejector, BuildableComponentIdResolveResult result) {
    if (dependency.getSelector() instanceof ProjectComponentSelector) {
        ProjectComponentSelector selector = (ProjectComponentSelector) dependency.getSelector();
        ProjectComponentIdentifier projectId = componentIdentifierFactory.createProjectComponentIdentifier(selector);
        LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(projectId);
        if (componentMetaData == null) {
            result.failed(new ModuleVersionResolveException(selector, () -> projectId + " not found."));
        } else {
            if (rejector != null && rejector.accept(componentMetaData.getModuleVersionId().getVersion())) {
                result.rejected(projectId, componentMetaData.getModuleVersionId());
            } else {
                result.resolved(componentMetaData);
            }
        }
    }
}
Also used : ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 22 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class ProjectDependencyResolver method resolve.

@Override
public void resolve(ComponentIdentifier identifier, ComponentOverrideMetadata componentOverrideMetadata, final BuildableComponentResolveResult result) {
    if (isProjectModule(identifier)) {
        ProjectComponentIdentifier projectId = (ProjectComponentIdentifier) identifier;
        LocalComponentMetadata componentMetaData = localComponentRegistry.getComponent(projectId);
        if (componentMetaData == null) {
            result.failed(new ModuleVersionResolveException(DefaultProjectComponentSelector.newSelector(projectId), () -> projectId + " not found."));
        } else {
            result.resolved(componentMetaData);
        }
    }
}
Also used : LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ProjectComponentIdentifier(org.gradle.api.artifacts.component.ProjectComponentIdentifier)

Example 23 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class EdgeState method getFailure.

@Override
public ModuleVersionResolveException getFailure() {
    if (targetNodeSelectionFailure != null) {
        return targetNodeSelectionFailure;
    }
    ModuleVersionResolveException selectorFailure = selector.getFailure();
    if (selectorFailure != null) {
        return selectorFailure;
    }
    ComponentState selectedComponent = getSelectedComponent();
    if (selectedComponent == null) {
        ModuleSelectors<SelectorState> selectors = selector.getTargetModule().getSelectors();
        for (SelectorState state : selectors) {
            selectorFailure = state.getFailure();
            if (selectorFailure != null) {
                return selectorFailure;
            }
        }
        throw new IllegalStateException("Expected to find a selector with a failure but none was found");
    }
    return selectedComponent.getMetadataResolveFailure();
}
Also used : ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException)

Example 24 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class EdgeState method calculateTargetConfigurations.

private void calculateTargetConfigurations(ComponentState targetComponent) {
    ComponentResolveMetadata targetModuleVersion = targetComponent.getMetadata();
    targetNodes.clear();
    targetNodeSelectionFailure = null;
    if (targetModuleVersion == null) {
        targetComponent.getModule().getPlatformState().addOrphanEdge(this);
        // Broken version
        return;
    }
    if (isConstraint && !isVirtualDependency()) {
        List<NodeState> nodes = targetComponent.getNodes();
        for (NodeState node : nodes) {
            if (node.isSelected()) {
                targetNodes.add(node);
            }
        }
        if (targetNodes.isEmpty()) {
            // There is a chance we could not attach target configurations previously
            List<EdgeState> unattachedDependencies = targetComponent.getModule().getUnattachedDependencies();
            if (!unattachedDependencies.isEmpty()) {
                for (EdgeState otherEdge : unattachedDependencies) {
                    if (otherEdge != this && !otherEdge.isConstraint()) {
                        otherEdge.attachToTargetConfigurations();
                        if (otherEdge.targetNodeSelectionFailure != null) {
                            // Copy selection failure
                            this.targetNodeSelectionFailure = otherEdge.targetNodeSelectionFailure;
                            return;
                        }
                        break;
                    }
                }
            }
            for (NodeState node : nodes) {
                if (node.isSelected()) {
                    targetNodes.add(node);
                }
            }
        }
        return;
    }
    List<ConfigurationMetadata> targetConfigurations;
    try {
        ImmutableAttributes attributes = resolveState.getRoot().getMetadata().getAttributes();
        attributes = resolveState.getAttributesFactory().concat(attributes, safeGetAttributes());
        targetConfigurations = dependencyMetadata.selectConfigurations(attributes, targetModuleVersion, resolveState.getAttributesSchema(), dependencyState.getDependency().getSelector().getRequestedCapabilities());
    } catch (AttributeMergingException mergeError) {
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), () -> {
            Attribute<?> attribute = mergeError.getAttribute();
            Object constraintValue = mergeError.getLeftValue();
            Object dependencyValue = mergeError.getRightValue();
            return "Inconsistency between attributes of a constraint and a dependency, on attribute '" + attribute + "' : dependency requires '" + dependencyValue + "' while constraint required '" + constraintValue + "'";
        });
        return;
    } catch (Exception t) {
        // Failure to select the target variant/configurations from this component, given the dependency attributes/metadata.
        targetNodeSelectionFailure = new ModuleVersionResolveException(dependencyState.getRequested(), t);
        return;
    }
    for (ConfigurationMetadata targetConfiguration : targetConfigurations) {
        NodeState targetNodeState = resolveState.getNode(targetComponent, targetConfiguration);
        this.targetNodes.add(targetNodeState);
    }
}
Also used : ImmutableAttributes(org.gradle.api.internal.attributes.ImmutableAttributes) ComponentResolveMetadata(org.gradle.internal.component.model.ComponentResolveMetadata) ConfigurationMetadata(org.gradle.internal.component.model.ConfigurationMetadata) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) AttributeMergingException(org.gradle.api.internal.attributes.AttributeMergingException) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) AttributeMergingException(org.gradle.api.internal.attributes.AttributeMergingException)

Example 25 with ModuleVersionResolveException

use of org.gradle.internal.resolve.ModuleVersionResolveException in project gradle by gradle.

the class DependencyGraphBuilder method markDeniedDynamicVersions.

private void markDeniedDynamicVersions(ComponentState cs) {
    for (NodeState node : cs.getNodes()) {
        List<EdgeState> incomingEdges = node.getIncomingEdges();
        for (EdgeState incomingEdge : incomingEdges) {
            ComponentSelector selector = incomingEdge.getSelector().getSelector();
            incomingEdge.failWith(new ModuleVersionResolveException(selector, () -> String.format("Could not resolve %s: Resolution strategy disallows usage of dynamic versions", selector)));
        }
    }
}
Also used : ComponentSelector(org.gradle.api.artifacts.component.ComponentSelector) ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException)

Aggregations

ModuleVersionResolveException (org.gradle.internal.resolve.ModuleVersionResolveException)28 ModuleComponentSelector (org.gradle.api.artifacts.component.ModuleComponentSelector)7 ProjectComponentIdentifier (org.gradle.api.artifacts.component.ProjectComponentIdentifier)7 LocalComponentMetadata (org.gradle.internal.component.local.model.LocalComponentMetadata)7 ProjectComponentSelector (org.gradle.api.artifacts.component.ProjectComponentSelector)5 DefaultProjectComponentSelector (org.gradle.internal.component.local.model.DefaultProjectComponentSelector)5 ArrayList (java.util.ArrayList)4 ComponentSelector (org.gradle.api.artifacts.component.ComponentSelector)4 DependencySubstitutionInternal (org.gradle.api.internal.artifacts.DependencySubstitutionInternal)3 ComponentResolveMetadata (org.gradle.internal.component.model.ComponentResolveMetadata)3 File (java.io.File)2 ComponentMetadataDetails (org.gradle.api.artifacts.ComponentMetadataDetails)2 ModuleVersionIdentifier (org.gradle.api.artifacts.ModuleVersionIdentifier)2 ModuleVersionSelector (org.gradle.api.artifacts.ModuleVersionSelector)2 BuildIdentifier (org.gradle.api.artifacts.component.BuildIdentifier)2 DependencySubstitutionApplicator (org.gradle.api.internal.artifacts.ivyservice.dependencysubstitution.DependencySubstitutionApplicator)2 ImmutableAttributes (org.gradle.api.internal.attributes.ImmutableAttributes)2 Pair (org.gradle.internal.Pair)2 ModuleComponentResolveMetadata (org.gradle.internal.component.external.model.ModuleComponentResolveMetadata)2 MutableModuleComponentResolveMetadata (org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata)2