How do I accomplish a task that triggers cleanup in subprojects without using aggregation?

I want to make a request cleanAll

that does a task clean

for multiple subprojects. I don't want to use aggregation just for clean

.

We were having problems with the routes of the game assets when we were using submodules.

Well documented how to create a new task, but how can I call the task in a subproject?

+3


source to share


2 answers


Using Jacek Laskowski as an example, I came up with the following plugin, which should be placed in a folder /project

:

import sbt._
import sbt.AutoPlugin
import sbt.Keys._
import sbt.plugins.JvmPlugin

object CleanAllPlugin extends AutoPlugin {

  val cleanAll = taskKey[Unit]("Cleans all projects in a build, regardless of dependencies")

  override def requires = JvmPlugin

  override def projectSettings = Seq(
    cleanAllTask
  )

  def cleanAllTask = cleanAll := Def.taskDyn {
    val allProjects = ScopeFilter(inAnyProject)
    clean.all(allProjects)
  }.value
}

      

The plugin can now be added to the root project for use:



val main = Project("root", file("."))
  .enablePlugins(CleanAllPlugin)

      

It can be executed in SBT by calling: cleanAll

+3


source


Use the following build.sbt

:

val selectDeps = ScopeFilter(inDependencies(ThisProject))

clean in Compile := clean.all(selectDeps).value

      

It is assumed that the file build.sbt

is in the project, which clean

is executed by itself and dependsOn

projects.

If you need it in project/Build.scala

, just add the following:



val selectDeps = ScopeFilter(inDependencies(ThisProject))
val cleanInSubprojects = Seq(
  clean in Compile := clean.all(selectDeps).value
)

      

and add cleanInSubprojects

to the settings of each project:

// definition of a project goes here
  .settings(cleanInSubprojects: _*)

      

+1


source







All Articles