summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Ernst <ryan@iernst.net>2017-05-25 12:22:08 -0700
committerRyan Ernst <ryan@iernst.net>2017-05-25 12:27:57 -0700
commitb5ea0cf3f831217393cba4536c7430c531aa919c (patch)
treecaa4369d74bd0ac808ffa523e8c166a754f398f6
parent61805a0f357580364bdf4fb63c732b888e0778a6 (diff)
Build: Add back explicit exclusions and remove gradle exclusions (#24879)
When transitive dependencies are disable for a dependency, gradle adds a wildcard exclusion to the generated pom. However, some external tools like ivy have bugs with wildcards. This commit adds back the explicit generation of transitive excludes, and removes the gradle generated exclusions element from the pom. closes #24490
-rw-r--r--buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy50
1 files changed, 47 insertions, 3 deletions
diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy
index b3c2f4faef..fc7c9c1e8a 100644
--- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy
+++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/BuildPlugin.groovy
@@ -311,7 +311,13 @@ class BuildPlugin implements Plugin<Project> {
/**
* Returns a closure which can be used with a MavenPom for fixing problems with gradle generated poms.
*
- * The current fixup is to set compile time deps back to compile from runtime (known issue with maven-publish plugin).
+ * <ul>
+ * <li>Remove transitive dependencies. We currently exclude all artifacts explicitly instead of using wildcards
+ * as Ivy incorrectly translates POMs with * excludes to Ivy XML with * excludes which results in the main artifact
+ * being excluded as well (see https://issues.apache.org/jira/browse/IVY-1531). Note that Gradle 2.14+ automatically
+ * translates non-transitive dependencies to * excludes. We should revisit this when upgrading Gradle.</li>
+ * <li>Set compile time deps back to compile from runtime (known issue with maven-publish plugin)</li>
+ * </ul>
*/
private static Closure fixupDependencies(Project project) {
return { XmlProvider xml ->
@@ -321,15 +327,53 @@ class BuildPlugin implements Plugin<Project> {
return
}
- // fix deps incorrectly marked as runtime back to compile time deps
- // see https://discuss.gradle.org/t/maven-publish-plugin-generated-pom-making-dependency-scope-runtime/7494/4
+ // check each dependency for any transitive deps
for (Node depNode : depsNodes.get(0).children()) {
+ String groupId = depNode.get('groupId').get(0).text()
+ String artifactId = depNode.get('artifactId').get(0).text()
+ String version = depNode.get('version').get(0).text()
+
+ // fix deps incorrectly marked as runtime back to compile time deps
+ // see https://discuss.gradle.org/t/maven-publish-plugin-generated-pom-making-dependency-scope-runtime/7494/4
boolean isCompileDep = project.configurations.compile.allDependencies.find { dep ->
dep.name == depNode.artifactId.text()
}
if (depNode.scope.text() == 'runtime' && isCompileDep) {
depNode.scope*.value = 'compile'
}
+
+ // remove any exclusions added by gradle, they contain wildcards and systems like ivy have bugs with wildcards
+ // see https://github.com/elastic/elasticsearch/issues/24490
+ NodeList exclusionsNode = depNode.get('exclusions')
+ if (exclusionsNode.size() > 0) {
+ depNode.remove(exclusionsNode.get(0))
+ }
+
+ // collect the transitive deps now that we know what this dependency is
+ String depConfig = transitiveDepConfigName(groupId, artifactId, version)
+ Configuration configuration = project.configurations.findByName(depConfig)
+ if (configuration == null) {
+ continue // we did not make this dep non-transitive
+ }
+ Set<ResolvedArtifact> artifacts = configuration.resolvedConfiguration.resolvedArtifacts
+ if (artifacts.size() <= 1) {
+ // this dep has no transitive deps (or the only artifact is itself)
+ continue
+ }
+
+ // we now know we have something to exclude, so add exclusions for all artifacts except the main one
+ Node exclusions = depNode.appendNode('exclusions')
+ for (ResolvedArtifact artifact : artifacts) {
+ ModuleVersionIdentifier moduleVersionIdentifier = artifact.moduleVersion.id;
+ String depGroupId = moduleVersionIdentifier.group
+ String depArtifactId = moduleVersionIdentifier.name
+ // add exclusions for all artifacts except the main one
+ if (depGroupId != groupId || depArtifactId != artifactId) {
+ Node exclusion = exclusions.appendNode('exclusion')
+ exclusion.appendNode('groupId', depGroupId)
+ exclusion.appendNode('artifactId', depArtifactId)
+ }
+ }
}
}
}