Search in sources :

Example 6 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class DefaultIvyPublication method populateDependencies.

private void populateDependencies(Set<? extends UsageContext> usageContexts, PublicationWarningsCollector publicationWarningsCollector) {
    for (UsageContext usageContext : usageContexts) {
        publicationWarningsCollector.newContext(usageContext.getName());
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            String confMapping = confMappingFor(usageContext, dependency);
            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, confMapping);
            } else {
                ExternalDependency externalDependency = (ExternalDependency) dependency;
                if (platformSupport.isTargetingPlatform(dependency)) {
                    publicationWarningsCollector.addUnsupported(String.format("%s:%s:%s declared as platform", dependency.getGroup(), dependency.getName(), dependency.getVersion()));
                }
                if (!versionMappingInUse && externalDependency.getVersion() == null) {
                    publicationWarningsCollector.addUnsupported(String.format("%s:%s declared without version", externalDependency.getGroup(), externalDependency.getName()));
                }
                addExternalDependency(externalDependency, confMapping, ((AttributeContainerInternal) usageContext.getAttributes()).asImmutable());
            }
        }
        if (!usageContext.getDependencyConstraints().isEmpty()) {
            for (DependencyConstraint constraint : usageContext.getDependencyConstraints()) {
                publicationWarningsCollector.addUnsupported(String.format("%s:%s:%s declared as a dependency constraint", constraint.getGroup(), constraint.getName(), constraint.getVersion()));
            }
        }
        if (!usageContext.getCapabilities().isEmpty()) {
            for (Capability capability : usageContext.getCapabilities()) {
                publicationWarningsCollector.addVariantUnsupported(String.format("Declares capability %s:%s:%s which cannot be mapped to Ivy", capability.getGroup(), capability.getName(), capability.getVersion()));
            }
        }
    }
}
Also used : ExternalDependency(org.gradle.api.artifacts.ExternalDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) Capability(org.gradle.api.capabilities.Capability) UsageContext(org.gradle.api.internal.component.UsageContext) DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint) DefaultIvyProjectDependency(org.gradle.api.publish.ivy.internal.dependency.DefaultIvyProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 7 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class DefaultDependencyHandler method testFixtures.

@Override
public Dependency testFixtures(Object notation) {
    Dependency testFixturesDependency = create(notation);
    if (testFixturesDependency instanceof ProjectDependency) {
        ProjectDependency projectDependency = (ProjectDependency) testFixturesDependency;
        projectDependency.capabilities(new ProjectTestFixtures(projectDependency.getDependencyProject()));
    } else if (testFixturesDependency instanceof ModuleDependency) {
        ModuleDependency moduleDependency = (ModuleDependency) testFixturesDependency;
        moduleDependency.capabilities(capabilities -> capabilities.requireCapability(new ImmutableCapability(moduleDependency.getGroup(), moduleDependency.getName() + TEST_FIXTURES_CAPABILITY_APPENDIX, null)));
    }
    return testFixturesDependency;
}
Also used : ComponentModuleMetadataHandler(org.gradle.api.artifacts.dsl.ComponentModuleMetadataHandler) ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) ARTIFACT_TYPE_ATTRIBUTE(org.gradle.api.artifacts.type.ArtifactTypeDefinition.ARTIFACT_TYPE_ATTRIBUTE) ListProperty(org.gradle.api.provider.ListProperty) Closure(groovy.lang.Closure) ExternalModuleDependencyVariantSpec(org.gradle.api.artifacts.dsl.ExternalModuleDependencyVariantSpec) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) ConfigureUtil(org.gradle.util.internal.ConfigureUtil) AttributesSchema(org.gradle.api.attributes.AttributesSchema) Provider(org.gradle.api.provider.Provider) ConfigurationContainer(org.gradle.api.artifacts.ConfigurationContainer) Map(java.util.Map) DeprecationLogger(org.gradle.internal.deprecation.DeprecationLogger) Transformer(org.gradle.api.Transformer) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) TEST_FIXTURES_CAPABILITY_APPENDIX(org.gradle.internal.component.external.model.TestFixturesSupport.TEST_FIXTURES_CAPABILITY_APPENDIX) MethodMixIn(org.gradle.internal.metaobject.MethodMixIn) MinimalExternalModuleDependency(org.gradle.api.artifacts.MinimalExternalModuleDependency) MethodAccess(org.gradle.internal.metaobject.MethodAccess) ProjectTestFixtures(org.gradle.internal.component.external.model.ProjectTestFixtures) ModuleDependencyCapabilitiesHandler(org.gradle.api.artifacts.ModuleDependencyCapabilitiesHandler) Collectors(java.util.stream.Collectors) TransformParameters(org.gradle.api.artifacts.transform.TransformParameters) List(java.util.List) Factory(org.gradle.internal.Factory) TransformAction(org.gradle.api.artifacts.transform.TransformAction) Category(org.gradle.api.attributes.Category) DefaultValueSourceProviderFactory(org.gradle.api.internal.provider.DefaultValueSourceProviderFactory) Inject(javax.inject.Inject) Configuration(org.gradle.api.artifacts.Configuration) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) AttributeContainer(org.gradle.api.attributes.AttributeContainer) ArtifactResolutionQuery(org.gradle.api.artifacts.query.ArtifactResolutionQuery) HasConfigurableAttributes(org.gradle.api.attributes.HasConfigurableAttributes) ArtifactResolutionQueryFactory(org.gradle.api.internal.artifacts.query.ArtifactResolutionQueryFactory) Nullable(javax.annotation.Nullable) Action(org.gradle.api.Action) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) VariantTransformRegistry(org.gradle.api.internal.artifacts.VariantTransformRegistry) DependencyConstraintHandler(org.gradle.api.artifacts.dsl.DependencyConstraintHandler) DefaultMinimalDependencyVariant(org.gradle.api.internal.artifacts.dependencies.DefaultMinimalDependencyVariant) Cast(org.gradle.internal.Cast) DependencyBundleValueSource(org.gradle.api.internal.catalog.DependencyBundleValueSource) ComponentMetadataHandler(org.gradle.api.artifacts.dsl.ComponentMetadataHandler) ProviderConvertible(org.gradle.api.provider.ProviderConvertible) ObjectFactory(org.gradle.api.model.ObjectFactory) ValueSource(org.gradle.api.provider.ValueSource) ArtifactTypeContainer(org.gradle.api.artifacts.type.ArtifactTypeContainer) InvalidUserDataException(org.gradle.api.InvalidUserDataException) Dependency(org.gradle.api.artifacts.Dependency) TransformSpec(org.gradle.api.artifacts.transform.TransformSpec) Actions(org.gradle.internal.Actions) ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) MinimalExternalModuleDependency(org.gradle.api.artifacts.MinimalExternalModuleDependency) ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) MinimalExternalModuleDependency(org.gradle.api.artifacts.MinimalExternalModuleDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Dependency(org.gradle.api.artifacts.Dependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) ImmutableCapability(org.gradle.internal.component.external.model.ImmutableCapability) ProjectTestFixtures(org.gradle.internal.component.external.model.ProjectTestFixtures)

Example 8 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class DefaultDependencyHandler method platform.

@Override
public Dependency platform(Object notation) {
    Dependency dependency = create(notation);
    if (dependency instanceof ModuleDependency) {
        ModuleDependency moduleDependency = (ModuleDependency) dependency;
        moduleDependency.endorseStrictVersions();
        platformSupport.addPlatformAttribute(moduleDependency, toCategory(Category.REGULAR_PLATFORM));
    } else if (dependency instanceof HasConfigurableAttributes) {
        platformSupport.addPlatformAttribute((HasConfigurableAttributes<?>) dependency, toCategory(Category.REGULAR_PLATFORM));
    }
    return dependency;
}
Also used : ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) MinimalExternalModuleDependency(org.gradle.api.artifacts.MinimalExternalModuleDependency) HasConfigurableAttributes(org.gradle.api.attributes.HasConfigurableAttributes) ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) MinimalExternalModuleDependency(org.gradle.api.artifacts.MinimalExternalModuleDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) Dependency(org.gradle.api.artifacts.Dependency)

Example 9 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class ModuleFactoryDelegate method dependency.

@SuppressWarnings("rawtypes")
public void dependency(Object dependencyNotation, Closure configureClosure) {
    Dependency dependency = dependencyFactory.createDependency(dependencyNotation);
    clientModule.addDependency((ModuleDependency) dependency);
    ConfigureUtil.configure(configureClosure, dependency);
}
Also used : Dependency(org.gradle.api.artifacts.Dependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency)

Example 10 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project gradle by gradle.

the class TransientConfigurationResultsBuilder method deserialize.

private TransientConfigurationResults deserialize(Decoder decoder, ResolvedGraphResults graphResults, SelectedArtifactResults artifactResults) {
    Timer clock = Timers.startTimer();
    Map<Long, DefaultResolvedDependency> allDependencies = new HashMap<Long, DefaultResolvedDependency>();
    Map<ModuleDependency, DependencyGraphNodeResult> firstLevelDependencies = new LinkedHashMap<ModuleDependency, DependencyGraphNodeResult>();
    DependencyGraphNodeResult root;
    int valuesRead = 0;
    byte type = -1;
    try {
        while (true) {
            type = decoder.readByte();
            long id;
            valuesRead++;
            switch(type) {
                case NEW_DEP:
                    id = decoder.readSmallLong();
                    ResolvedConfigurationIdentifier details = resolvedConfigurationIdentifierSerializer.read(decoder);
                    allDependencies.put(id, new DefaultResolvedDependency(id, details));
                    break;
                case ROOT:
                    id = decoder.readSmallLong();
                    root = allDependencies.get(id);
                    if (root == null) {
                        throw new IllegalStateException(String.format("Unexpected root id %s. Seen ids: %s", id, allDependencies.keySet()));
                    }
                    //root should be the last entry
                    LOG.debug("Loaded resolved configuration results ({}) from {}", clock.getElapsed(), binaryStore);
                    return new DefaultTransientConfigurationResults(root, firstLevelDependencies);
                case FIRST_LVL:
                    id = decoder.readSmallLong();
                    DefaultResolvedDependency dependency = allDependencies.get(id);
                    if (dependency == null) {
                        throw new IllegalStateException(String.format("Unexpected first level id %s. Seen ids: %s", id, allDependencies.keySet()));
                    }
                    firstLevelDependencies.put(graphResults.getModuleDependency(id), dependency);
                    break;
                case PARENT_CHILD:
                    long parentId = decoder.readSmallLong();
                    long childId = decoder.readSmallLong();
                    DefaultResolvedDependency parent = allDependencies.get(parentId);
                    DefaultResolvedDependency child = allDependencies.get(childId);
                    if (parent == null) {
                        throw new IllegalStateException(String.format("Unexpected parent dependency id %s. Seen ids: %s", parentId, allDependencies.keySet()));
                    }
                    if (child == null) {
                        throw new IllegalStateException(String.format("Unexpected child dependency id %s. Seen ids: %s", childId, allDependencies.keySet()));
                    }
                    parent.addChild(child);
                    child.addParentSpecificArtifacts(parent, artifactResults.getArtifacts(decoder.readSmallLong()));
                    break;
                default:
                    throw new IOException("Unknown value type read from stream: " + type);
            }
        }
    } catch (IOException e) {
        throw new RuntimeException("Problems loading the resolved configuration. Read " + valuesRead + " values, last was: " + type, e);
    }
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DefaultResolvedDependency(org.gradle.api.internal.artifacts.DefaultResolvedDependency) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) DependencyGraphNodeResult(org.gradle.api.internal.artifacts.DependencyGraphNodeResult) Timer(org.gradle.internal.time.Timer) ResolvedConfigurationIdentifier(org.gradle.api.internal.artifacts.ResolvedConfigurationIdentifier)

Aggregations

ModuleDependency (org.gradle.api.artifacts.ModuleDependency)25 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)8 Dependency (org.gradle.api.artifacts.Dependency)6 Test (org.junit.Test)5 Closure (groovy.lang.Closure)3 InvalidUserDataException (org.gradle.api.InvalidUserDataException)3 DependencyConstraint (org.gradle.api.artifacts.DependencyConstraint)3 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)3 PublishArtifact (org.gradle.api.artifacts.PublishArtifact)3 UsageContext (org.gradle.api.internal.component.UsageContext)3 HashMap (java.util.HashMap)2 ExcludeRule (org.gradle.api.artifacts.ExcludeRule)2 ExternalDependency (org.gradle.api.artifacts.ExternalDependency)2 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)2 MinimalExternalModuleDependency (org.gradle.api.artifacts.MinimalExternalModuleDependency)2 HasConfigurableAttributes (org.gradle.api.attributes.HasConfigurableAttributes)2 Capability (org.gradle.api.capabilities.Capability)2 DefaultExcludeRule (org.gradle.api.internal.artifacts.DefaultExcludeRule)2 MavenDependency (org.gradle.api.publish.maven.MavenDependency)2 DefaultMavenDependency (org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency)2