Search in sources :

Example 16 with ModuleDependency

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

the class ModuleMetadataFileGenerator method writeDependency.

private void writeDependency(Dependency dependency, JsonWriter jsonWriter) throws IOException {
    jsonWriter.beginObject();
    if (dependency instanceof ProjectDependency) {
        ProjectDependency projectDependency = (ProjectDependency) dependency;
        ModuleVersionIdentifier identifier = projectDependencyResolver.resolve(ModuleVersionIdentifier.class, projectDependency);
        jsonWriter.name("group");
        jsonWriter.value(identifier.getGroup());
        jsonWriter.name("module");
        jsonWriter.value(identifier.getName());
        writeVersionConstraint(DefaultImmutableVersionConstraint.of(identifier.getVersion()), jsonWriter);
    } else {
        jsonWriter.name("group");
        jsonWriter.value(dependency.getGroup());
        jsonWriter.name("module");
        jsonWriter.value(dependency.getName());
        VersionConstraint vc;
        if (dependency instanceof ModuleVersionSelector) {
            vc = ((ExternalDependency) dependency).getVersionConstraint();
        } else {
            vc = DefaultImmutableVersionConstraint.of(Strings.nullToEmpty(dependency.getVersion()));
        }
        writeVersionConstraint(vc, jsonWriter);
    }
    if (dependency instanceof ModuleDependency) {
        writeExcludes((ModuleDependency) dependency, jsonWriter);
    }
    String reason = dependency.getReason();
    if (StringUtils.isNotEmpty(reason)) {
        jsonWriter.name("reason");
        jsonWriter.value(reason);
    }
    jsonWriter.endObject();
}
Also used : ModuleVersionIdentifier(org.gradle.api.artifacts.ModuleVersionIdentifier) VersionConstraint(org.gradle.api.artifacts.VersionConstraint) DefaultImmutableVersionConstraint(org.gradle.api.internal.artifacts.dependencies.DefaultImmutableVersionConstraint) ModuleVersionSelector(org.gradle.api.artifacts.ModuleVersionSelector) ModuleDependency(org.gradle.api.artifacts.ModuleDependency) ProjectDependency(org.gradle.api.artifacts.ProjectDependency)

Example 17 with ModuleDependency

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

the class ModuleMetadataFileGenerator method writeDependencies.

private void writeDependencies(UsageContext variant, JsonWriter jsonWriter) throws IOException {
    if (variant.getDependencies().isEmpty()) {
        return;
    }
    jsonWriter.name("dependencies");
    jsonWriter.beginArray();
    for (ModuleDependency moduleDependency : variant.getDependencies()) {
        writeDependency(moduleDependency, jsonWriter);
    }
    jsonWriter.endArray();
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency)

Example 18 with ModuleDependency

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

the class DefaultMavenPublication method from.

public void from(SoftwareComponent component) {
    if (this.component != null) {
        throw new InvalidUserDataException(String.format("Maven publication '%s' cannot include multiple components", name));
    }
    this.component = (SoftwareComponentInternal) component;
    Set<ArtifactKey> seenArtifacts = Sets.newHashSet();
    Set<ModuleDependency> seenDependencies = Sets.newHashSet();
    Set<DependencyConstraint> seenConstraints = Sets.newHashSet();
    for (UsageContext usageContext : getSortedUsageContexts()) {
        // TODO Need a smarter way to map usage to artifact classifier
        for (PublishArtifact publishArtifact : usageContext.getArtifacts()) {
            ArtifactKey key = new ArtifactKey(publishArtifact.getFile(), publishArtifact.getClassifier(), publishArtifact.getExtension());
            if (seenArtifacts.add(key)) {
                artifact(publishArtifact);
            }
        }
        Set<MavenDependencyInternal> dependencies = dependenciesFor(usageContext.getUsage());
        for (ModuleDependency dependency : usageContext.getDependencies()) {
            if (seenDependencies.add(dependency)) {
                if (dependency instanceof ProjectDependency) {
                    addProjectDependency((ProjectDependency) dependency, dependencies);
                } else {
                    addModuleDependency(dependency, dependencies);
                }
            }
        }
        Set<MavenDependency> dependencyConstraints = dependencyConstraintsFor(usageContext.getUsage());
        for (DependencyConstraint dependency : usageContext.getDependencyConstraints()) {
            if (seenConstraints.add(dependency) && !dependency.getVersionConstraint().getPreferredVersion().isEmpty()) {
                addDependencyConstraint(dependency, dependencyConstraints);
            }
        }
    }
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) DependencyConstraint(org.gradle.api.artifacts.DependencyConstraint) ProjectDependency(org.gradle.api.artifacts.ProjectDependency) MavenDependencyInternal(org.gradle.api.publish.maven.internal.dependencies.MavenDependencyInternal) UsageContext(org.gradle.api.internal.component.UsageContext) InvalidUserDataException(org.gradle.api.InvalidUserDataException) PublishArtifact(org.gradle.api.artifacts.PublishArtifact) DefaultMavenDependency(org.gradle.api.publish.maven.internal.dependencies.DefaultMavenDependency) MavenDependency(org.gradle.api.publish.maven.MavenDependency)

Example 19 with ModuleDependency

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

the class CreateDependencyInfoFile method createDependencyInfoFile.

public void createDependencyInfoFile(CreateDependencyInfoFileTask task) {
    String result = "# Description" + NEWLINE + DESCRIPTION + NEWLINE + "# Dependencies";
    // sorting dependencies to assure that they are always in the same order
    // without depending on Gradle implementation
    SortedSet<String> dependencies = new TreeSet<>();
    for (Dependency dependency : task.getConfiguration().getAllDependencies()) {
        if (dependency instanceof ModuleDependency) {
            String dep = getDependencyWithArtifacts(task, (ModuleDependency) dependency);
            dependencies.add(dep);
        }
    }
    result += DEPENDENCY_INDENT + StringUtil.join(dependencies, DEPENDENCY_INDENT);
    IOUtil.writeFile(task.getOutputFile(), result.toString());
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) TreeSet(java.util.TreeSet) Dependency(org.gradle.api.artifacts.Dependency) ModuleDependency(org.gradle.api.artifacts.ModuleDependency)

Example 20 with ModuleDependency

use of org.gradle.api.artifacts.ModuleDependency in project checkstyle-idea by jshiell.

the class CheckstyleVersions method createCheckstyleDependency.

public static Dependency createCheckstyleDependency(final Project pProject, final String pCheckstyleVersion) {
    final ModuleDependency csDep = (ModuleDependency) pProject.getDependencies().create("com.puppycrawl.tools:checkstyle:" + pCheckstyleVersion);
    final Map<String, String> ex = new HashMap<>();
    ex.put("group", "commons-logging");
    ex.put("module", "commons-logging");
    csDep.exclude(ex);
    return csDep;
}
Also used : ModuleDependency(org.gradle.api.artifacts.ModuleDependency) HashMap(java.util.HashMap)

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