From cfe3b801e1b9694b66d8942a2bfa12a7ed0788f8 Mon Sep 17 00:00:00 2001 From: Jaroslaw Grabowski Date: Fri, 26 Aug 2016 11:35:13 +0200 Subject: [PATCH] Support wildcard exclusions in maven resolver The idea here is that if a dependency contains exclude with wildcards than it is inTransitive. --- ...ugin-transitive-wildcard-excludes.markdown | 12 +++++++++ project/Dependencies.scala | 2 +- .../mavenint/MavenRepositoryResolver.scala | 25 +++++++++++-------- .../{pending => test} | 0 4 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 notes/0.13.13/maven-plugin-transitive-wildcard-excludes.markdown rename sbt/src/sbt-test/dependency-management/transitive-wildcard-excludes/{pending => test} (100%) diff --git a/notes/0.13.13/maven-plugin-transitive-wildcard-excludes.markdown b/notes/0.13.13/maven-plugin-transitive-wildcard-excludes.markdown new file mode 100644 index 000000000..be0cd68a7 --- /dev/null +++ b/notes/0.13.13/maven-plugin-transitive-wildcard-excludes.markdown @@ -0,0 +1,12 @@ +[@jtgrabowski]: https://github.com/jtgrabowski +[1431]: https://github.com/sbt/sbt/issues/1431 +[sbt-ivy-22]: https://github.com/sbt/ivy/pull/22 +[2731]: https://github.com/sbt/sbt/pull/2731 + +### Fixes with compatibility implications + +### Improvements + +### Bug fixes + +- Support wildcard exclusions when using sbt-maven-resolver-plugin [#1431][1431][sbt/ivy#22][sbt-ivy-22]/[#2731][2731] by [@jtgrabowski][@jtgrabowski] diff --git a/project/Dependencies.scala b/project/Dependencies.scala index ad08b92ab..1c77b9162 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -9,7 +9,7 @@ object Dependencies { lazy val scala211 = "2.11.7" lazy val jline = "jline" % "jline" % "2.13" - lazy val ivy = "org.scala-sbt.ivy" % "ivy" % "2.3.0-sbt-2cc8d2761242b072cedb0a04cb39435c4fa24f9a" + lazy val ivy = "org.scala-sbt.ivy" % "ivy" % "2.3.0-sbt-2cf13e211b2cb31f0d3b317289dca70eca3362f6" lazy val jsch = "com.jcraft" % "jsch" % "0.1.50" intransitive () lazy val sbinary = "org.scala-tools.sbinary" %% "sbinary" % "0.4.2" lazy val sbtSerialization = "org.scala-sbt" %% "serialization" % "0.1.2" diff --git a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositoryResolver.scala b/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositoryResolver.scala index e550b9c0a..5b36c41aa 100644 --- a/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositoryResolver.scala +++ b/sbt-maven-resolver/src/main/scala/sbt/mavenint/MavenRepositoryResolver.scala @@ -357,11 +357,12 @@ abstract class MavenRepositoryResolver(settings: IvySettings) extends AbstractRe case _ => tmp } } + val transitive = d.getExclusions.asScala.forall(e => e.getGroupId != "*" || e.getArtifactId != "*") // Note: The previous maven integration ALWAYS set force to true for dependnecies. If we do not do this, for some // reason, Ivy will create dummy nodes when doing dependnecy mediation (e.g. dependencyManagement of one pom overrides version of a dependency) // which was leading to "data not found" exceptions as Ivy would pick the correct IvyNode in the dependency tree but never load it with data.... - val dd = new DefaultDependencyDescriptor(md, drid, /* force */ true, isChanging, true) {} + val dd = new DefaultDependencyDescriptor(md, drid, /* force */ true, isChanging, transitive) {} // TODO - Configuration mappings (are we grabbing scope correctly, or should the default not always be compile?) val scope = Option(d.getScope).filterNot(_.isEmpty).getOrElse("compile") @@ -389,16 +390,18 @@ abstract class MavenRepositoryResolver(settings: IvySettings) extends AbstractRe // TOOD - We may need to fix the configuration mappings here. dd.addDependencyArtifact(optionalizedScope, depArtifact) } - // Include rules and exclude rules. - for (e <- d.getExclusions.asScala) { - val excludedModule = new ModuleId(e.getGroupId, e.getArtifactId) - for (conf <- dd.getModuleConfigurations) { - // TODO - Do we need extra attributes for this? - dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId( - excludedModule, PatternMatcher.ANY_EXPRESSION, - PatternMatcher.ANY_EXPRESSION, - PatternMatcher.ANY_EXPRESSION), - ExactPatternMatcher.INSTANCE, null)) + if (dd.isTransitive) { + // Include rules and exclude rules. + for (e <- d.getExclusions.asScala) { + val excludedModule = new ModuleId(e.getGroupId, e.getArtifactId) + for (conf <- dd.getModuleConfigurations) { + // TODO - Do we need extra attributes for this? + dd.addExcludeRule(conf, new DefaultExcludeRule(new ArtifactId( + excludedModule, PatternMatcher.ANY_EXPRESSION, + PatternMatcher.ANY_EXPRESSION, + PatternMatcher.ANY_EXPRESSION), + ExactPatternMatcher.INSTANCE, null)) + } } } md.addDependency(dd) diff --git a/sbt/src/sbt-test/dependency-management/transitive-wildcard-excludes/pending b/sbt/src/sbt-test/dependency-management/transitive-wildcard-excludes/test similarity index 100% rename from sbt/src/sbt-test/dependency-management/transitive-wildcard-excludes/pending rename to sbt/src/sbt-test/dependency-management/transitive-wildcard-excludes/test