Search in sources :

Example 51 with Dependency

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

the class DefaultDependencyHandler method doAddRegularDependency.

private Dependency doAddRegularDependency(Configuration configuration, Object dependencyNotation, Closure<?> configureClosure) {
    Dependency dependency = create(dependencyNotation, configureClosure);
    configuration.getDependencies().add(dependency);
    return dependency;
}
Also used : 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 52 with Dependency

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

the class DefaultDependencyHandler method enforcedPlatform.

@Override
@SuppressWarnings("deprecation")
public Dependency enforcedPlatform(Object notation) {
    Dependency platformDependency = create(notation);
    if (platformDependency instanceof ExternalModuleDependency) {
        ExternalModuleDependency externalModuleDependency = (ExternalModuleDependency) platformDependency;
        DeprecationLogger.whileDisabled(() -> externalModuleDependency.setForce(true));
        platformSupport.addPlatformAttribute(externalModuleDependency, toCategory(Category.ENFORCED_PLATFORM));
    } else if (platformDependency instanceof HasConfigurableAttributes) {
        platformSupport.addPlatformAttribute((HasConfigurableAttributes<?>) platformDependency, toCategory(Category.ENFORCED_PLATFORM));
    }
    return platformDependency;
}
Also used : 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) ExternalModuleDependency(org.gradle.api.artifacts.ExternalModuleDependency) MinimalExternalModuleDependency(org.gradle.api.artifacts.MinimalExternalModuleDependency)

Example 53 with Dependency

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

the class TransientConfigurationResultsBuilder method deserialize.

private TransientConfigurationResults deserialize(Decoder decoder, ResolvedGraphResults graphResults, SelectedArtifactResults artifactResults, BuildOperationExecutor buildOperationProcessor) {
    Timer clock = Time.startTimer();
    Map<Long, DefaultResolvedDependency> allDependencies = new HashMap<>();
    Map<Dependency, DependencyGraphNodeResult> firstLevelDependencies = new LinkedHashMap<>();
    DependencyGraphNodeResult root;
    int valuesRead = 0;
    byte type = -1;
    long id;
    ResolvedArtifactSet artifacts;
    try {
        while (true) {
            type = decoder.readByte();
            valuesRead++;
            switch(type) {
                case NODE:
                    id = decoder.readSmallLong();
                    ResolvedConfigurationIdentifier details = resolvedConfigurationIdentifierSerializer.read(decoder);
                    allDependencies.put(id, new DefaultResolvedDependency(details, buildOperationProcessor));
                    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_LEVEL:
                    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 EDGE:
                    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);
                    artifacts = artifactResults.getArtifactsWithId(decoder.readSmallInt());
                    child.addParentSpecificArtifacts(parent, artifacts);
                    break;
                case NODE_ARTIFACTS:
                    id = decoder.readSmallLong();
                    DefaultResolvedDependency node = allDependencies.get(id);
                    if (node == null) {
                        throw new IllegalStateException(String.format("Unexpected node id %s. Seen ids: %s", node, allDependencies.keySet()));
                    }
                    artifacts = artifactResults.getArtifactsWithId(decoder.readSmallInt());
                    node.addModuleArtifacts(artifacts);
                    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 : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ResolvedArtifactSet(org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ResolvedArtifactSet) DefaultResolvedDependency(org.gradle.api.internal.artifacts.DefaultResolvedDependency) DefaultResolvedDependency(org.gradle.api.internal.artifacts.DefaultResolvedDependency) Dependency(org.gradle.api.artifacts.Dependency) 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)

Example 54 with Dependency

use of org.gradle.api.artifacts.Dependency in project gradle-eta by typelead.

the class EtaInjectDependencies method dependsOnProjects.

public void dependsOnProjects() {
    dependsOn(new Callable<List<Buildable>>() {

        @Override
        public List<Buildable> call() {
            return getProject().getConfigurations().getByName(getTargetConfiguration()).getAllDependencies().stream().filter(dependency -> dependency instanceof ProjectDependency).flatMap(dependency -> {
                final ProjectDependency projectDependency = (ProjectDependency) dependency;
                final Project project = projectDependency.getDependencyProject();
                final String configurationName = projectDependency.getTargetConfiguration();
                return ConfigurationUtils.getConfiguration(project, configurationName).getAllArtifacts().stream();
            }).collect(Collectors.toList());
        }
    });
}
Also used : Buildable(org.gradle.api.Buildable) Project(org.gradle.api.Project) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ExtensionHelper(com.typelead.gradle.utils.ExtensionHelper) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Callable(java.util.concurrent.Callable) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Configuration(org.gradle.api.artifacts.Configuration) TaskAction(org.gradle.api.tasks.TaskAction) List(java.util.List) Provider(org.gradle.api.provider.Provider) EtaDependency(com.typelead.gradle.eta.api.EtaDependency) ConfigurationUtils(com.typelead.gradle.eta.internal.ConfigurationUtils) DependencyHandler(org.gradle.api.artifacts.dsl.DependencyHandler) DefaultTask(org.gradle.api.DefaultTask) EtaBasePlugin(com.typelead.gradle.eta.plugins.EtaBasePlugin) Input(org.gradle.api.tasks.Input) DefaultEtaConfiguration(com.typelead.gradle.eta.internal.DefaultEtaConfiguration) Dependency(org.gradle.api.artifacts.Dependency) Project(org.gradle.api.Project) ArrayList(java.util.ArrayList) List(java.util.List) EtaProjectDependency(com.typelead.gradle.eta.api.EtaProjectDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 55 with Dependency

use of org.gradle.api.artifacts.Dependency in project atlas by alibaba.

the class AtlasProjectDependencyManager method addProjectDependency.

public static void addProjectDependency(Project project, String variantName) {
    Task task = project.getTasks().findByName("prepare" + variantName + "Dependencies");
    if (null == task) {
        return;
    }
    DependencySet dependencies = project.getConfigurations().getByName(AtlasPlugin.BUNDLE_COMPILE).getDependencies();
    if (null == dependencies) {
        return;
    }
    dependencies.forEach(new Consumer<Dependency>() {

        @Override
        public void accept(Dependency dependency) {
            if (dependency instanceof DefaultProjectDependency) {
                Project subProject = ((DefaultProjectDependency) dependency).getDependencyProject();
                Task assembleTask = subProject.getTasks().findByName("assembleRelease");
                task.dependsOn(assembleTask);
            }
        }
    });
}
Also used : Project(org.gradle.api.Project) Task(org.gradle.api.Task) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) DependencySet(org.gradle.api.artifacts.DependencySet) DefaultProjectDependency(org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency) Dependency(org.gradle.api.artifacts.Dependency)

Aggregations

Dependency (org.gradle.api.artifacts.Dependency)58 Configuration (org.gradle.api.artifacts.Configuration)20 ProjectDependency (org.gradle.api.artifacts.ProjectDependency)16 File (java.io.File)13 Project (org.gradle.api.Project)13 ModuleDependency (org.gradle.api.artifacts.ModuleDependency)12 ExternalModuleDependency (org.gradle.api.artifacts.ExternalModuleDependency)8 MinimalExternalModuleDependency (org.gradle.api.artifacts.MinimalExternalModuleDependency)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 FileCollectionDependency (org.gradle.api.artifacts.FileCollectionDependency)6 Collectors (java.util.stream.Collectors)5 Inject (javax.inject.Inject)5 DependencySet (org.gradle.api.artifacts.DependencySet)5 ObjectFactory (org.gradle.api.model.ObjectFactory)5 TaskDependency (org.gradle.api.tasks.TaskDependency)5 EtaDependency (com.typelead.gradle.eta.api.EtaDependency)4 EtaProjectDependency (com.typelead.gradle.eta.api.EtaProjectDependency)4 Map (java.util.Map)4 Provider (org.gradle.api.provider.Provider)4