mirror of https://github.com/sbt/sbt.git
Support for simple exclusion rules in inline dependencies
This support excluding a library from the dependency tree for a given
set of `ExclusionRule`s. There are two ways to achieve this:
- Using `organization` and `name` pairs:
val dep = "org" % "name" % "version" exclude("commons-codec", "commons-codec") exclude("org.slf4j", "slf4j-log4j")
- Using `ExclusionRule`:
val dep = "org" % "name" % "version" excludeAll(ExclusionRule("commons-codec", "commons-codec"), ExclusionRule("org.slf4j", "slf4j-log4j"))
This commit is contained in:
parent
496c6c1ef2
commit
a6396f839b
|
|
@ -419,6 +419,13 @@ private object IvySbt
|
||||||
for(conf <- dependencyDescriptor.getModuleConfigurations)
|
for(conf <- dependencyDescriptor.getModuleConfigurations)
|
||||||
dependencyDescriptor.addDependencyArtifact(conf, ivyArtifact)
|
dependencyDescriptor.addDependencyArtifact(conf, ivyArtifact)
|
||||||
}
|
}
|
||||||
|
for(excls <- dependency.exclusions)
|
||||||
|
{
|
||||||
|
for(conf <- dependencyDescriptor.getModuleConfigurations)
|
||||||
|
{
|
||||||
|
dependencyDescriptor.addExcludeRule(conf, IvyScala.excludeRule(excls.organization, excls.name, excls.configurations))
|
||||||
|
}
|
||||||
|
}
|
||||||
moduleID.addDependency(dependencyDescriptor)
|
moduleID.addDependency(dependencyDescriptor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import scala.xml.NodeSeq
|
||||||
import org.apache.ivy.plugins.resolver.{DependencyResolver, IBiblioResolver}
|
import org.apache.ivy.plugins.resolver.{DependencyResolver, IBiblioResolver}
|
||||||
import org.apache.ivy.util.url.CredentialsStore
|
import org.apache.ivy.util.url.CredentialsStore
|
||||||
|
|
||||||
final case class ModuleID(organization: String, name: String, revision: String, configurations: Option[String] = None, isChanging: Boolean = false, isTransitive: Boolean = true, explicitArtifacts: Seq[Artifact] = Nil, extraAttributes: Map[String,String] = Map.empty, crossVersion: Boolean = false)
|
final case class ModuleID(organization: String, name: String, revision: String, configurations: Option[String] = None, isChanging: Boolean = false, isTransitive: Boolean = true, explicitArtifacts: Seq[Artifact] = Nil, exclusions: Seq[ExclusionRule] = Nil, extraAttributes: Map[String,String] = Map.empty, crossVersion: Boolean = false)
|
||||||
{
|
{
|
||||||
override def toString =
|
override def toString =
|
||||||
organization + ":" + name + ":" + revision +
|
organization + ":" + name + ":" + revision +
|
||||||
|
|
@ -24,6 +24,8 @@ final case class ModuleID(organization: String, name: String, revision: String,
|
||||||
def from(url: String) = artifacts(Artifact(name, new URL(url)))
|
def from(url: String) = artifacts(Artifact(name, new URL(url)))
|
||||||
def classifier(c: String) = artifacts(Artifact(name, c))
|
def classifier(c: String) = artifacts(Artifact(name, c))
|
||||||
def artifacts(newArtifacts: Artifact*) = copy(explicitArtifacts = newArtifacts ++ this.explicitArtifacts)
|
def artifacts(newArtifacts: Artifact*) = copy(explicitArtifacts = newArtifacts ++ this.explicitArtifacts)
|
||||||
|
def excludeAll(rules: ExclusionRule*) = copy(exclusions = this.exclusions ++ rules)
|
||||||
|
def exclude(org: String, name: String) = excludeAll(ExclusionRule(org, name))
|
||||||
def extra(attributes: (String,String)*) = copy(extraAttributes = this.extraAttributes ++ ModuleID.checkE(attributes))
|
def extra(attributes: (String,String)*) = copy(extraAttributes = this.extraAttributes ++ ModuleID.checkE(attributes))
|
||||||
def sources() = artifacts(Artifact.sources(name))
|
def sources() = artifacts(Artifact.sources(name))
|
||||||
def javadoc() = artifacts(Artifact.javadoc(name))
|
def javadoc() = artifacts(Artifact.javadoc(name))
|
||||||
|
|
@ -46,6 +48,8 @@ case class ModuleInfo(nameFormal: String, description: String = "", homepage: Op
|
||||||
def licensed(lics: (String, URL)*) = copy(licenses = lics)
|
def licensed(lics: (String, URL)*) = copy(licenses = lics)
|
||||||
def organization(name: String, home: Option[URL]) = copy(organizationName = name, organizationHomepage = home)
|
def organization(name: String, home: Option[URL]) = copy(organizationName = name, organizationHomepage = home)
|
||||||
}
|
}
|
||||||
|
/** Rule to exclude unwanted dependencies pulled in transitively by a module. */
|
||||||
|
case class ExclusionRule(organization: String = "*", name: String = "*", artifact: String = "*", configurations: Seq[String] = Nil)
|
||||||
sealed trait Resolver
|
sealed trait Resolver
|
||||||
{
|
{
|
||||||
def name: String
|
def name: String
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ private object IvyScala
|
||||||
}
|
}
|
||||||
/** Creates an ExcludeRule that excludes artifacts with the given module organization and name for
|
/** Creates an ExcludeRule that excludes artifacts with the given module organization and name for
|
||||||
* the given configurations. */
|
* the given configurations. */
|
||||||
private def excludeRule(organization: String, name: String, configurationNames: Iterable[String]): ExcludeRule =
|
private[sbt] def excludeRule(organization: String, name: String, configurationNames: Iterable[String]): ExcludeRule =
|
||||||
{
|
{
|
||||||
val artifact = new ArtifactId(ModuleId.newInstance(organization, name), "*", "jar", "*")
|
val artifact = new ArtifactId(ModuleId.newInstance(organization, name), "*", "jar", "*")
|
||||||
val rule = new DefaultExcludeRule(artifact, ExactPatternMatcher.INSTANCE, emptyMap[AnyRef,AnyRef])
|
val rule = new DefaultExcludeRule(artifact, ExactPatternMatcher.INSTANCE, emptyMap[AnyRef,AnyRef])
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue