Skip to content

Commit

Permalink
Update sbt to 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrohdezma authored Oct 5, 2020
1 parent 2649faa commit b330e12
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 32 deletions.
10 changes: 0 additions & 10 deletions .mergify.yml

This file was deleted.

7 changes: 4 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
ThisBuild / scalaVersion := "2.12.11"
ThisBuild / organization := "com.alejandrohdezma"
ThisBuild / scalaVersion := "2.12.12"
ThisBuild / organization := "com.alejandrohdezma"
ThisBuild / pluginCrossBuild / sbtVersion := "1.2.8"

addCommandAlias("ci-test", "fix --check; mdoc; scripted")
addCommandAlias("ci-docs", "github; mdoc; headerCreateAll")
addCommandAlias("ci-publish", "github; ci-release")

lazy val documentation = project
.enablePlugins(MdocPlugin)
.dependsOn(allModules: _*)
.dependsOn(allModules)
.settings(mdocOut := file("."))

lazy val `sbt-modules` = module
Expand Down
8 changes: 5 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
lazy val docs = project
- .settings(skip in publish := true)
- .dependsOn(allProjects: _*)
+ .dependsOn(allModules: _*)
+ .dependsOn(allModules)
.in(file("docs"))

+ lazy val `my-library-core` = module
Expand Down Expand Up @@ -67,13 +67,15 @@ Would expect the following directory structure:
`sbt-modules` creates a special variable called `allModules` that aggregates all the modules created with `module`, so you can pass it along as a dependency to other projects in your build, like:

```sbt
lazy val documentation = project.dependsOn(allModules: _*)
lazy val documentation = project.dependsOn(allModules)

lazy val `my-library-core` = module

lazy val `my-library-plugin` = module.dependsOn(`my-library-core`)
```

> Important ‼️ The `allModules` variable is created by listing all the directories in the `modules` directory so ensure: (1) that all your modules have a corresponding directory inside `modules` and (2) that there are no directories inside `modules` that aren't a module.
### Auto-`skip in publish`

Forget about setting `skip in publish := true` again. Adding this plugin to your build will disable publishing for all the projects in the build (including the auto-generated root plugin), except for those created with `module`.
Expand All @@ -84,7 +86,7 @@ Example:

```sbt
// Will not be published
lazy val documentation = project.dependsOn(allmodules: _*)
lazy val documentation = project.dependsOn(allmodules)

// Will be published
lazy val `my-library-plugin` = module.dependsOn(`my-library-core`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,53 @@

package com.alejandrohdezma.sbt.modules

import scala.collection.mutable
import scala.language.experimental.macros
import scala.reflect.macros._

import sbt.Keys._
import sbt._

@SuppressWarnings(Array("scalafix:Disable.scala.collection.mutable", "scalafix:DisableSyntax.implicitConversion"))
@SuppressWarnings(
Array(
"scalafix:Disable.scala.collection.mutable",
"scalafix:DisableSyntax.implicitConversion",
"scalafix:Disable.blocking.io"
)
)
object ModulesPlugin extends AutoPlugin {

override def trigger = allRequirements

object autoImport {

/** List of all modules created with [[module]] */
val allModules: mutable.MutableList[Project] = mutable.MutableList[Project]()
implicit class ProjectOpsWithProjectReferenceList(private val project: Project) extends AnyVal {

/** Adds classpath dependencies on internal or external projects. */
def dependsOn(deps: List[ProjectReference]): Project =
project.dependsOn(deps: _*)

/**
* Adds projects to be aggregated. When a user requests a task to run on this project from the command line,
* the task will also be run in aggregated projects.
*/
def aggregate(refs: List[ProjectReference]): Project =
project.aggregate(refs: _*)

}

implicit def MutableListProject2ListClasspathDependency(
list: mutable.MutableList[Project]
/** List of all modules created with [[module]] */
val allModules: List[ProjectReference] =
Option(file("./modules"))
.filter(_.isDirectory())
.fold(List.empty[File])(_.listFiles.toList)
.filter(_.isDirectory())
.map(_.getName())
.map(LocalProject(_))

implicit def ListProject2ListClasspathDependency(
list: List[ProjectReference]
): List[ClasspathDep[ProjectReference]] =
list.map(classpathDependency(_)).toList
list.map(classpathDependency(_))

/**
* Creates a new Project with `modules` as base directory.
Expand Down Expand Up @@ -64,12 +90,7 @@ object ModulesPlugin extends AutoPlugin {
val name = c.Expr[String](Literal(Constant(enclosingValName)))

reify {
val project = Project(name.splice, file("modules") / name.splice)
.settings(skip in publish := false)

ModulesPlugin.autoImport.allModules += project

project
Project(name.splice, file("modules") / name.splice).settings(skip in publish := false)
}
}

Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ lazy val c = project.dependsOn(allModules: _*)

TaskKey[Unit]("check", "Checks c depends on a & b using `allModules`") := {
val expected = List(
ClasspathDependency(LocalProject("b"), None),
ClasspathDependency(LocalProject("a"), None)
ClasspathDependency(LocalProject("a"), None),
ClasspathDependency(LocalProject("b"), None)
)

assert(c.dependencies == expected, s"Found: ${c.dependencies}\nExpected: $expected")
Expand Down
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.3.13
sbt.version=1.4.0

0 comments on commit b330e12

Please sign in to comment.