Search in sources :

Example 16 with ModuleVersionResolveException

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

the class DefaultIncludedBuildTaskGraph method checkNoCycles.

private void checkNoCycles(BuildIdentifier sourceBuild, BuildIdentifier targetBuild, List<BuildIdentifier> candidateCycle) {
    candidateCycle.add(targetBuild);
    for (BuildIdentifier nextTarget : buildDependencies.get(targetBuild)) {
        if (sourceBuild.equals(nextTarget)) {
            candidateCycle.add(nextTarget);
            ProjectComponentSelector selector = DefaultProjectComponentSelector.newSelector(candidateCycle.get(0), Path.ROOT.getPath());
            throw new ModuleVersionResolveException(selector, "Included build dependency cycle: " + reportCycle(candidateCycle));
        }
        checkNoCycles(sourceBuild, nextTarget, candidateCycle);
    }
    candidateCycle.remove(targetBuild);
}
Also used : DefaultProjectComponentSelector(org.gradle.internal.component.local.model.DefaultProjectComponentSelector) ProjectComponentSelector(org.gradle.api.artifacts.component.ProjectComponentSelector) BuildIdentifier(org.gradle.api.artifacts.component.BuildIdentifier) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException)

Example 17 with ModuleVersionResolveException

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

the class LocalLibraryDependencyResolver method resolveLibraryAndChooseBinary.

private void resolveLibraryAndChooseBinary(BuildableComponentIdResolveResult result, LibraryComponentSelector selector) {
    final String selectorProjectPath = selector.getProjectPath();
    final String libraryName = selector.getLibraryName();
    final String variant = selector.getVariant();
    LibraryResolutionResult resolutionResult = doResolve(selectorProjectPath, libraryName);
    VariantComponent selectedLibrary = resolutionResult.getSelectedLibrary();
    if (selectedLibrary == null) {
        String message = resolutionResult.toResolutionErrorMessage(selector);
        ModuleVersionResolveException failure = new ModuleVersionResolveException(selector, new LibraryResolveException(message));
        result.failed(failure);
        return;
    }
    final Collection<? extends Binary> matchingVariants = chooseMatchingVariants(selectedLibrary, variant);
    if (matchingVariants.isEmpty()) {
        // no compatible variant found
        final Iterable<? extends Binary> values = selectedLibrary.getVariants();
        result.failed(new ModuleVersionResolveException(selector, new Factory<String>() {

            @Nullable
            @Override
            public String create() {
                return errorMessageBuilder.noCompatibleVariantErrorMessage(libraryName, values);
            }
        }));
    } else if (matchingVariants.size() > 1) {
        result.failed(new ModuleVersionResolveException(selector, new Factory<String>() {

            @Nullable
            @Override
            public String create() {
                return errorMessageBuilder.multipleCompatibleVariantsErrorMessage(libraryName, matchingVariants);
            }
        }));
    } else {
        Binary selectedBinary = matchingVariants.iterator().next();
        // TODO:Cedric This is not quite right. We assume that if we are asking for a specific binary, then we resolve to the assembly instead
        // of the jar, but it should be somehow parameterized
        LocalComponentMetadata metaData;
        if (variant == null) {
            metaData = libraryMetaDataAdapter.createLocalComponentMetaData(selectedBinary, selectorProjectPath, false);
        } else {
            metaData = libraryMetaDataAdapter.createLocalComponentMetaData(selectedBinary, selectorProjectPath, true);
        }
        result.resolved(metaData);
    }
}
Also used : CalculatedValueContainerFactory(org.gradle.internal.model.CalculatedValueContainerFactory) Factory(org.gradle.internal.Factory) LibraryResolveException(org.gradle.language.base.internal.resolve.LibraryResolveException) LocalComponentMetadata(org.gradle.internal.component.local.model.LocalComponentMetadata) VariantComponent(org.gradle.platform.base.VariantComponent) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) Binary(org.gradle.platform.base.Binary) Nullable(javax.annotation.Nullable)

Example 18 with ModuleVersionResolveException

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

the class DefaultComponentMetadataProcessor method processMetadata.

@Override
public ComponentMetadata processMetadata(ComponentMetadata metadata) {
    ComponentMetadata updatedMetadata;
    if (metadataRuleContainer.isEmpty()) {
        updatedMetadata = metadata;
    } else {
        ShallowComponentMetadataAdapter details = new ShallowComponentMetadataAdapter(componentIdentifierNotationParser, metadata, attributesFactory);
        processAllRules(null, details, metadata.getId());
        updatedMetadata = details.asImmutable();
    }
    if (!updatedMetadata.getStatusScheme().contains(updatedMetadata.getStatus())) {
        throw new ModuleVersionResolveException(updatedMetadata.getId(), () -> String.format("Unexpected status '%s' specified for %s. Expected one of: %s", updatedMetadata.getStatus(), updatedMetadata.getId().toString(), updatedMetadata.getStatusScheme()));
    }
    return updatedMetadata;
}
Also used : ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) ComponentMetadata(org.gradle.api.artifacts.ComponentMetadata)

Example 19 with ModuleVersionResolveException

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

the class DefaultComponentMetadataProcessor method processMetadata.

@Override
public ModuleComponentResolveMetadata processMetadata(ModuleComponentResolveMetadata origin) {
    VariantDerivationStrategy curStrategy = metadataRuleContainer.getVariantDerivationStrategy();
    ModuleComponentResolveMetadata metadata = origin.withDerivationStrategy(curStrategy);
    ModuleComponentResolveMetadata updatedMetadata;
    if (metadataRuleContainer.isEmpty()) {
        updatedMetadata = maybeForceRealisation(metadata);
    } else if (metadataRuleContainer.isClassBasedRulesOnly()) {
        Action<ComponentMetadataContext> action = collectRulesAndCreateAction(metadataRuleContainer.getOnlyClassRules(), metadata.getModuleVersionId(), metadataResolutionContext.getInjectingInstantiator());
        if (action instanceof InstantiatingAction) {
            InstantiatingAction<ComponentMetadataContext> ia = (InstantiatingAction<ComponentMetadataContext>) action;
            if (shouldCacheComponentMetadataRule(ia, metadata)) {
                updatedMetadata = processClassRuleWithCaching(ia, metadata, metadataResolutionContext);
            } else {
                MutableModuleComponentResolveMetadata mutableMetadata = metadata.asMutable();
                processClassRule(action, metadata, createDetails(mutableMetadata));
                updatedMetadata = maybeForceRealisation(mutableMetadata.asImmutable());
            }
        } else {
            updatedMetadata = maybeForceRealisation(metadata);
        }
    } else {
        MutableModuleComponentResolveMetadata mutableMetadata = metadata.asMutable();
        ComponentMetadataDetails details = createDetails(mutableMetadata);
        processAllRules(metadata, details, metadata.getModuleVersionId());
        updatedMetadata = maybeForceRealisation(mutableMetadata.asImmutable());
    }
    if (!updatedMetadata.getStatusScheme().contains(updatedMetadata.getStatus())) {
        throw new ModuleVersionResolveException(updatedMetadata.getModuleVersionId(), () -> String.format("Unexpected status '%s' specified for %s. Expected one of: %s", updatedMetadata.getStatus(), updatedMetadata.getId().getDisplayName(), updatedMetadata.getStatusScheme()));
    }
    return updatedMetadata;
}
Also used : MutableModuleComponentResolveMetadata(org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata) MutableModuleComponentResolveMetadata(org.gradle.internal.component.external.model.MutableModuleComponentResolveMetadata) ModuleComponentResolveMetadata(org.gradle.internal.component.external.model.ModuleComponentResolveMetadata) Action(org.gradle.api.Action) InstantiatingAction(org.gradle.internal.action.InstantiatingAction) RuleAction(org.gradle.internal.rules.RuleAction) SpecRuleAction(org.gradle.internal.rules.SpecRuleAction) ComponentMetadataContext(org.gradle.api.artifacts.ComponentMetadataContext) ModuleVersionResolveException(org.gradle.internal.resolve.ModuleVersionResolveException) VariantDerivationStrategy(org.gradle.internal.component.external.model.VariantDerivationStrategy) InstantiatingAction(org.gradle.internal.action.InstantiatingAction) ComponentMetadataDetails(org.gradle.api.artifacts.ComponentMetadataDetails)

Example 20 with ModuleVersionResolveException

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

the class DynamicVersionResolver method resolve.

public void resolve(ModuleDependencyMetadata dependency, VersionSelector versionSelector, @Nullable VersionSelector rejectedVersionSelector, AttributeContainer consumerAttributes, BuildableComponentIdResolveResult result) {
    ModuleComponentSelector requested = dependency.getSelector();
    LOGGER.debug("Attempting to resolve version for {} using repositories {}", requested, repositoryNames);
    List<Throwable> errors = new ArrayList<>();
    List<RepositoryResolveState> resolveStates = Lists.newArrayListWithCapacity(repositories.size());
    for (ModuleComponentRepository repository : repositories) {
        resolveStates.add(new RepositoryResolveState(versionedComponentChooser, dependency, repository, versionSelector, rejectedVersionSelector, versionParser, consumerAttributes, attributesFactory, componentMetadataProcessor, componentMetadataSupplierRuleExecutor, cachePolicy));
    }
    final RepositoryChainModuleResolution latestResolved = findLatestModule(resolveStates, errors);
    if (latestResolved != null) {
        LOGGER.debug("Using {} from {}", latestResolved.module.getModuleVersionId(), latestResolved.repository);
        for (Throwable error : errors) {
            LOGGER.debug("Discarding resolve failure.", error);
        }
        found(result, resolveStates, latestResolved);
        return;
    }
    if (!errors.isEmpty()) {
        result.failed(new ModuleVersionResolveException(requested, errors));
    } else {
        notFound(result, requested, resolveStates);
    }
}
Also used : ModuleComponentSelector(org.gradle.api.artifacts.component.ModuleComponentSelector) ArrayList(java.util.ArrayList) 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