Print list of sub-projects

I’m trying to add a task for list all the sub-projects of a multi-project build. My root build.gradle.kts is:

allprojects {
  repositories {
    jcenter()
  }
}

subprojects {
  version = "1.0"

}

tasks.create("listProjects") {
  doLast {
    println(subprojects.forEach { println(it.name) })
  }
}

when run, out put contains an extra line with “kotlin.Unit”.

k8s-demo % ./gradlew listProjects

> Task :listProjects
connect
kotlin.Unit

BUILD SUCCESSFUL in 4s

My settings file looks like:

rootProject.name = "k8s-demo"

include(
  "connect"
)

for (project in rootProject.children) {
  project.apply {
    projectDir = file("./_projects/${name}")
    buildFileName = "multi-build.gradle.kts"
  }
}

Any idea how to fix list so kotlin.Unit is removed?

Thanks in advance.

You have a duplicated “println” there. :slight_smile: Remove the one in the beginning of the line.

subprojects.forEach { println(it.name) }

Thanks so much!!! I can’t believe I missed that :frowning:

1 Like