@@ -23,7 +23,6 @@ import com.github.jengelman.gradle.plugins.shadow.ShadowBasePlugin
2323import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
2424import com.github.jengelman.gradle.plugins.shadow.ShadowJavaPlugin
2525import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
26- import groovy.transform.CompileDynamic
2726import groovy.transform.CompileStatic
2827import org.apache.commons.io.IOUtils
2928import org.elasticsearch.gradle.info.GlobalBuildInfoPlugin
@@ -42,13 +41,10 @@ import org.gradle.api.NamedDomainObjectContainer
4241import org.gradle.api.Plugin
4342import org.gradle.api.Project
4443import org.gradle.api.Task
45- import org.gradle.api.XmlProvider
4644import org.gradle.api.artifacts.Configuration
4745import org.gradle.api.artifacts.Dependency
4846import org.gradle.api.artifacts.ModuleDependency
49- import org.gradle.api.artifacts.ModuleVersionIdentifier
5047import org.gradle.api.artifacts.ProjectDependency
51- import org.gradle.api.artifacts.ResolvedArtifact
5248import org.gradle.api.artifacts.dsl.RepositoryHandler
5349import org.gradle.api.artifacts.repositories.IvyArtifactRepository
5450import org.gradle.api.artifacts.repositories.IvyPatternRepositoryLayout
@@ -331,11 +327,6 @@ class BuildPlugin implements Plugin<Project> {
331327 return javaVersions. find { it. version == version }. javaHome. absolutePath
332328 }
333329
334- /* * Return the configuration name used for finding transitive deps of the given dependency. */
335- private static String transitiveDepConfigName (String groupId , String artifactId , String version ) {
336- return " _transitive_${ groupId} _${ artifactId} _${ version} "
337- }
338-
339330 /**
340331 * Makes dependencies non-transitive.
341332 *
@@ -362,11 +353,6 @@ class BuildPlugin implements Plugin<Project> {
362353 }
363354 // fail on any conflicting dependency versions
364355 project. configurations. all({ Configuration configuration ->
365- if (configuration. name. startsWith(' _transitive_' )) {
366- // don't force transitive configurations to not conflict with themselves, since
367- // we just have them to find *what* transitive deps exist
368- return
369- }
370356 if (configuration. name. endsWith(' Fixture' )) {
371357 // just a self contained test-fixture configuration, likely transitive and hellacious
372358 return
@@ -381,14 +367,6 @@ class BuildPlugin implements Plugin<Project> {
381367 if (dep instanceof ModuleDependency && ! (dep instanceof ProjectDependency )
382368 && dep. group. startsWith(' org.elasticsearch' ) == false ) {
383369 dep. transitive = false
384-
385- // also create a configuration just for this dependency version, so that later
386- // we can determine which transitive dependencies it has
387- String depConfig = transitiveDepConfigName(dep. group, dep. name, dep. version)
388- if (project. configurations. findByName(depConfig) == null ) {
389- project. configurations. create(depConfig)
390- project. dependencies. add(depConfig, " ${ dep.group} :${ dep.name} :${ dep.version} " )
391- }
392370 }
393371 }
394372
@@ -458,77 +436,6 @@ class BuildPlugin implements Plugin<Project> {
458436 }
459437 }
460438
461- /**
462- * Returns a closure which can be used with a MavenPom for fixing problems with gradle generated poms.
463- *
464- * <ul >
465- * <li >Remove transitive dependencies. We currently exclude all artifacts explicitly instead of using wildcards
466- * as Ivy incorrectly translates POMs with * excludes to Ivy XML with * excludes which results in the main artifact
467- * being excluded as well (see https://issues.apache.org/jira/browse/IVY-1531). Note that Gradle 2.14+ automatically
468- * translates non-transitive dependencies to * excludes. We should revisit this when upgrading Gradle.</li>
469- * <li >Set compile time deps back to compile from runtime (known issue with maven-publish plugin)</li>
470- * </ul>
471- */
472- @CompileDynamic
473- private static Closure fixupDependencies (Project project ) {
474- return { XmlProvider xml ->
475- // first find if we have dependencies at all, and grab the node
476- NodeList depsNodes = xml. asNode(). get(' dependencies' )
477- if (depsNodes. isEmpty()) {
478- return
479- }
480-
481- // check each dependency for any transitive deps
482- for (Node depNode : depsNodes. get(0 ). children()) {
483- String groupId = depNode. get(' groupId' ). get(0 ). text()
484- String artifactId = depNode. get(' artifactId' ). get(0 ). text()
485- String version = depNode. get(' version' ). get(0 ). text()
486-
487- // fix deps incorrectly marked as runtime back to compile time deps
488- // see https://discuss.gradle.org/t/maven-publish-plugin-generated-pom-making-dependency-scope-runtime/7494/4
489- boolean isCompileDep = project. configurations. compile. allDependencies. find { dep ->
490- dep. name == depNode. artifactId. text()
491- }
492- if (depNode. scope. text() == ' runtime' && isCompileDep) {
493- depNode. scope* . value = ' compile'
494- }
495-
496- // remove any exclusions added by gradle, they contain wildcards and systems like ivy have bugs with wildcards
497- // see https://github.com/elastic/elasticsearch/issues/24490
498- NodeList exclusionsNode = depNode. get(' exclusions' )
499- if (exclusionsNode. size() > 0 ) {
500- depNode. remove(exclusionsNode. get(0 ))
501- }
502-
503- // collect the transitive deps now that we know what this dependency is
504- String depConfig = transitiveDepConfigName(groupId, artifactId, version)
505- Configuration configuration = project. configurations. findByName(depConfig)
506- if (configuration == null ) {
507- continue // we did not make this dep non-transitive
508- }
509- Set<ResolvedArtifact > artifacts = configuration. resolvedConfiguration. resolvedArtifacts
510- if (artifacts. size() <= 1 ) {
511- // this dep has no transitive deps (or the only artifact is itself)
512- continue
513- }
514-
515- // we now know we have something to exclude, so add exclusions for all artifacts except the main one
516- Node exclusions = depNode. appendNode(' exclusions' )
517- for (ResolvedArtifact artifact : artifacts) {
518- ModuleVersionIdentifier moduleVersionIdentifier = artifact. moduleVersion. id;
519- String depGroupId = moduleVersionIdentifier. group
520- String depArtifactId = moduleVersionIdentifier. name
521- // add exclusions for all artifacts except the main one
522- if (depGroupId != groupId || depArtifactId != artifactId) {
523- Node exclusion = exclusions. appendNode(' exclusion' )
524- exclusion. appendNode(' groupId' , depGroupId)
525- exclusion. appendNode(' artifactId' , depArtifactId)
526- }
527- }
528- }
529- }
530- }
531-
532439 /* *Configuration generation of maven poms. */
533440 static void configurePomGeneration (Project project ) {
534441 project. plugins. withType(MavenPublishPlugin ). whenPluginAdded {
@@ -546,11 +453,6 @@ class BuildPlugin implements Plugin<Project> {
546453
547454 PublishingExtension publishing = project. extensions. getByType(PublishingExtension )
548455
549- project. extensions. getByType(PublishingExtension ). publications. all { MavenPublication publication -> // we only deal with maven
550- // add exclusions to the pom directly, for each of the transitive deps of this project's deps
551- publication. pom. withXml(fixupDependencies(project))
552- }
553-
554456 project. pluginManager. withPlugin(' com.github.johnrengelman.shadow' ) {
555457 MavenPublication publication = publishing. publications. maybeCreate(' shadow' , MavenPublication )
556458 ShadowExtension shadow = project. extensions. getByType(ShadowExtension )
0 commit comments