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