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();
}
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();
}
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);
}
}
}
}
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());
}
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;
}
Aggregations