diff --git a/.mergify.yml b/.mergify.yml deleted file mode 100644 index 849a93b..0000000 --- a/.mergify.yml +++ /dev/null @@ -1,10 +0,0 @@ -pull_request_rules: - - name: automatically merge & label scala-steward's PRs - conditions: - - author=scala-steward - - status-success=test - actions: - merge: - method: squash - label: - add: [scala-steward] \ No newline at end of file diff --git a/build.sbt b/build.sbt index 95c6bd4..a3e1f78 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,6 @@ -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") @@ -7,7 +8,7 @@ addCommandAlias("ci-publish", "github; ci-release") lazy val documentation = project .enablePlugins(MdocPlugin) - .dependsOn(allModules: _*) + .dependsOn(allModules) .settings(mdocOut := file(".")) lazy val `sbt-modules` = module diff --git a/docs/README.md b/docs/README.md index 0787db4..424f943 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 @@ -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`. @@ -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`) diff --git a/modules/sbt-modules/src/main/scala/com/alejandrohdezma/sbt/modules/ModulesPlugin.scala b/modules/sbt-modules/src/main/scala/com/alejandrohdezma/sbt/modules/ModulesPlugin.scala index 932987b..09cf5c6 100644 --- a/modules/sbt-modules/src/main/scala/com/alejandrohdezma/sbt/modules/ModulesPlugin.scala +++ b/modules/sbt-modules/src/main/scala/com/alejandrohdezma/sbt/modules/ModulesPlugin.scala @@ -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. @@ -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) } } diff --git a/modules/sbt-modules/src/sbt-test/sbt-modules/all-modules/modules/a/.noop b/modules/sbt-modules/src/sbt-test/sbt-modules/all-modules/modules/a/.noop new file mode 100644 index 0000000..e69de29 diff --git a/modules/sbt-modules/src/sbt-test/sbt-modules/all-modules/modules/b/.noop b/modules/sbt-modules/src/sbt-test/sbt-modules/all-modules/modules/b/.noop new file mode 100644 index 0000000..e69de29 diff --git a/modules/sbt-modules/src/sbt-test/sbt-modules/all-modules/modules/c/.noop b/modules/sbt-modules/src/sbt-test/sbt-modules/all-modules/modules/c/.noop new file mode 100644 index 0000000..e69de29 diff --git a/modules/sbt-modules/src/sbt-test/sbt-modules/simple/modules/a/.noop b/modules/sbt-modules/src/sbt-test/sbt-modules/simple/modules/a/.noop new file mode 100644 index 0000000..e69de29 diff --git a/modules/sbt-modules/src/sbt-test/sbt-modules/simple/modules/b/.noop b/modules/sbt-modules/src/sbt-test/sbt-modules/simple/modules/b/.noop new file mode 100644 index 0000000..e69de29 diff --git a/modules/sbt-modules/src/sbt-test/sbt-modules/skip-in-publish/build.sbt b/modules/sbt-modules/src/sbt-test/sbt-modules/skip-in-publish/build.sbt index 9401f63..f652a2e 100644 --- a/modules/sbt-modules/src/sbt-test/sbt-modules/skip-in-publish/build.sbt +++ b/modules/sbt-modules/src/sbt-test/sbt-modules/skip-in-publish/build.sbt @@ -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") diff --git a/modules/sbt-modules/src/sbt-test/sbt-modules/skip-in-publish/modules/a/.noop b/modules/sbt-modules/src/sbt-test/sbt-modules/skip-in-publish/modules/a/.noop new file mode 100644 index 0000000..e69de29 diff --git a/modules/sbt-modules/src/sbt-test/sbt-modules/skip-in-publish/modules/b/.noop b/modules/sbt-modules/src/sbt-test/sbt-modules/skip-in-publish/modules/b/.noop new file mode 100644 index 0000000..e69de29 diff --git a/project/build.properties b/project/build.properties index 0837f7a..6db9842 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.13 +sbt.version=1.4.0