'Debug build.sbt as a Scala program

How can I debug (compile) build.sbt as a Scala program?

Working on a large Scala (sbt) project (36 sub-projects) that has not been updated in a while. Getting some strange compilation errors on build.sbt, having to do with the changes in the sbt API between sbt 0.13 and 1.5. Some expressions just will not compile, and I would like to take a closer look at the types. I would like to put the text of build.sbt inside a Scala file, to see why it does not compile.

The build (with some parts cut out) works using sbt from a Linux command line. But in IntelliJ it's all red (errors), all the types are shown as "Any", etc. So I cannot figure out why some expressions (currently commented out) will not compile.

I expect to be able to do something like this (in a different project, created for this purpose):

SomeFileName.scala
import sbt._ // What should I import here?
import sbt.Keys._

class SomeFileName {
    // paste the contents of the build.sbt file here
}

I expect this SomeFileName.scala to be a normal Scala class. Maybe it will have compilation errors, and I will be able to see exactly what they are, what the sbt API is, and figure out what is wrong with my build file.

How can I do that?



Solution 1:[1]

Figured it out. The expression that made things difficult was that we had a list of subprojects that was conditional. The solution was to call .project on them, as below:

val subProjects = if (...) Seq(proj1, proj2) else Seq(proj3, proj4)
lazy val root =  (project in file("."))
  .aggregate(subProjects.map(x => x.project) : _*)

This works fine in build.sbt, i.e. build.sbt compiles.

I have found it useful (as a debugging tool) to paste the content of build.sbt in a Scala file as shown in the question.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 radumanolescu