use of org.gradle.api.publish.maven.MavenDependency in project gradle by gradle.
the class MavenPomFileGenerator method addDependencyManagement.
private void addDependencyManagement(MavenDependency dependency, String scope) {
Dependency mavenDependency = new Dependency();
mavenDependency.setGroupId(dependency.getGroupId());
mavenDependency.setArtifactId(dependency.getArtifactId());
mavenDependency.setVersion(mapToMavenSyntax(dependency.getVersion()));
mavenDependency.setScope(scope);
DependencyManagement dependencyManagement = getModel().getDependencyManagement();
if (dependencyManagement == null) {
dependencyManagement = new DependencyManagement();
getModel().setDependencyManagement(dependencyManagement);
}
dependencyManagement.addDependency(mavenDependency);
}
use of org.gradle.api.publish.maven.MavenDependency in project gradle by gradle.
the class MavenPomFileGenerator method addDependency.
private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier, boolean optional) {
Dependency mavenDependency = new Dependency();
String groupId = dependency.getGroupId();
String dependencyVersion = dependency.getVersion();
String projectPath = dependency.getProjectPath();
ImmutableAttributes attributes = attributesForScope(scope);
ModuleVersionIdentifier resolvedVersion = versionMappingStrategy.findStrategyForVariant(attributes).maybeResolveVersion(groupId, artifactId, projectPath);
mavenDependency.setGroupId(resolvedVersion != null ? resolvedVersion.getGroup() : groupId);
mavenDependency.setArtifactId(resolvedVersion != null ? resolvedVersion.getName() : artifactId);
mavenDependency.setVersion(resolvedVersion != null ? resolvedVersion.getVersion() : mapToMavenSyntax(dependencyVersion));
mavenDependency.setType(type);
mavenDependency.setScope(scope);
mavenDependency.setClassifier(classifier);
if (optional) {
// Not using setOptional(optional) in order to avoid <optional>false</optional> in the common case
mavenDependency.setOptional(true);
}
for (ExcludeRule excludeRule : dependency.getExcludeRules()) {
Exclusion exclusion = new Exclusion();
exclusion.setGroupId(GUtil.elvis(excludeRule.getGroup(), "*"));
exclusion.setArtifactId(GUtil.elvis(excludeRule.getModule(), "*"));
mavenDependency.addExclusion(exclusion);
}
model.addDependency(mavenDependency);
}
use of org.gradle.api.publish.maven.MavenDependency 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.publish.maven.MavenDependency in project gradle by gradle.
the class MavenPomFileGenerator method addDependency.
private void addDependency(MavenDependencyInternal dependency, String artifactId, String scope, String type, String classifier) {
Dependency mavenDependency = new Dependency();
mavenDependency.setGroupId(dependency.getGroupId());
mavenDependency.setArtifactId(artifactId);
mavenDependency.setVersion(mapToMavenSyntax(dependency.getVersion()));
mavenDependency.setType(type);
mavenDependency.setScope(scope);
mavenDependency.setClassifier(classifier);
for (ExcludeRule excludeRule : dependency.getExcludeRules()) {
Exclusion exclusion = new Exclusion();
exclusion.setGroupId(GUtil.elvis(excludeRule.getGroup(), "*"));
exclusion.setArtifactId(GUtil.elvis(excludeRule.getModule(), "*"));
mavenDependency.addExclusion(exclusion);
}
getModel().addDependency(mavenDependency);
}
use of org.gradle.api.publish.maven.MavenDependency in project gradle by gradle.
the class GenerateMavenPom method doGenerate.
@TaskAction
public void doGenerate() {
MavenPomInternal pomInternal = (MavenPomInternal) getPom();
MavenPomFileGenerator pomGenerator = new MavenPomFileGenerator(pomInternal.getProjectIdentity(), getVersionRangeMapper());
pomGenerator.setPackaging(pomInternal.getPackaging());
for (MavenDependency mavenDependency : pomInternal.getApiDependencyManagement()) {
pomGenerator.addApiDependencyManagement(mavenDependency);
}
for (MavenDependency mavenDependency : pomInternal.getRuntimeDependencyManagement()) {
pomGenerator.addRuntimeDependencyManagement(mavenDependency);
}
for (MavenDependencyInternal runtimeDependency : pomInternal.getApiDependencies()) {
pomGenerator.addApiDependency(runtimeDependency);
}
for (MavenDependencyInternal runtimeDependency : pomInternal.getRuntimeDependencies()) {
pomGenerator.addRuntimeDependency(runtimeDependency);
}
pomGenerator.withXml(pomInternal.getXmlAction());
pomGenerator.writeTo(getDestination());
}
Aggregations