Skip to content

Commit

Permalink
add exclusions and custom configuration to dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
leakyabstraction committed Mar 21, 2018
1 parent 91188aa commit d0f6de2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 12 deletions.
14 changes: 14 additions & 0 deletions scalalib/src/mill/scalalib/Dep.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ import mill.util.JsonFormatters._
import upickle.default.{macroRW, ReadWriter => RW}
sealed trait Dep {
def configure(attributes: coursier.Attributes): Dep
def exclude(exclusions: (String, String)*): Dep =
this match {
case dep : Dep.Java => dep.copy(dep = dep.dep.copy(exclusions = dep.dep.exclusions ++ exclusions))
case dep : Dep.Scala => dep.copy(dep = dep.dep.copy(exclusions = dep.dep.exclusions ++ exclusions))
case dep : Dep.Point => dep.copy(dep = dep.dep.copy(exclusions = dep.dep.exclusions ++ exclusions))
}
def excludeOrg(organizations: String*): Dep = exclude(organizations.map(_ -> "*"): _*)
def excludeName(names: String*): Dep = exclude(names.map("*" -> _): _*)
def withConfiguration(configuration: String): Dep =
this match {
case dep : Dep.Java => dep.copy(dep = dep.dep.copy(configuration = configuration))
case dep : Dep.Scala => dep.copy(dep = dep.dep.copy(configuration = configuration))
case dep : Dep.Point => dep.copy(dep = dep.dep.copy(configuration = configuration))
}
}
object Dep{

Expand Down
8 changes: 6 additions & 2 deletions scalalib/src/mill/scalalib/publish/Ivy.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ object Ivy {
}

private def renderDependency(dep: Dependency) = {
val scope = scopeToConf(dep.scope)
<dependency org={dep.artifact.group} name={dep.artifact.id} rev={dep.artifact.version} conf={s"$scope->default(compile)"}></dependency>
if (dep.exclusions.isEmpty)
<dependency org={dep.artifact.group} name={dep.artifact.id} rev={dep.artifact.version} conf={s"${dep.scope}->default(${dep.configuration.getOrElse("compile")})"} />
else
<dependency org={dep.artifact.group} name={dep.artifact.id} rev={dep.artifact.version} conf={s"${dep.scope}->default(${dep.configuration.getOrElse("compile")})"}>
{dep.exclusions.map(ex => <exclude org={ex._1} name={ex._2} />).toSeq}
</dependency>
}

private def scopeToConf(s: Scope): String = s match {
Expand Down
28 changes: 22 additions & 6 deletions scalalib/src/mill/scalalib/publish/Pom.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,28 @@ object Pom {
case Scope.Test => <scope>test</scope>
case Scope.Runtime => <scope>runtime</scope>
}
<dependency>
<groupId>{d.artifact.group}</groupId>
<artifactId>{d.artifact.id}</artifactId>
<version>{d.artifact.version}</version>
{scope}
</dependency>
if (d.exclusions.isEmpty)
<dependency>
<groupId>{d.artifact.group}</groupId>
<artifactId>{d.artifact.id}</artifactId>
<version>{d.artifact.version}</version>
{scope}
</dependency>
else
<dependency>
<groupId>{d.artifact.group}</groupId>
<artifactId>{d.artifact.id}</artifactId>
<version>{d.artifact.version}</version>
<exclusions>
{d.exclusions.map(ex =>
<exclude>
<groupId>{ex._1}</groupId>
<artifactId>{ex._2}</artifactId>
</exclude>
)}.toSeq
</exclusions>
{scope}
</dependency>
}

}
16 changes: 12 additions & 4 deletions scalalib/src/mill/scalalib/publish/settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ object Artifact {
case Dep.Java(dep, cross) =>
Dependency(
Artifact(dep.module.organization, dep.module.name, dep.version),
Scope.Compile
Scope.Compile,
if (dep.configuration == "" ) None else Some(dep.configuration),
dep.exclusions
)
case Dep.Scala(dep, cross) =>
Dependency(
Expand All @@ -24,7 +26,9 @@ object Artifact {
s"${dep.module.name}_${scalaBin}",
dep.version
),
Scope.Compile
Scope.Compile,
if (dep.configuration == "") None else Some(dep.configuration),
dep.exclusions
)
case Dep.Point(dep, cross) =>
Dependency(
Expand All @@ -33,7 +37,9 @@ object Artifact {
s"${dep.module.name}_${scalaFull}",
dep.version
),
Scope.Compile
Scope.Compile,
if (dep.configuration == "") None else Some(dep.configuration),
dep.exclusions
)
}
}
Expand All @@ -49,7 +55,9 @@ object Scope {

case class Dependency(
artifact: Artifact,
scope: Scope
scope: Scope,
configuration: Option[String] = None,
exclusions: Set[(String, String)] = Set.empty
)

case class Developer(
Expand Down

0 comments on commit d0f6de2

Please sign in to comment.