I have some sub-projects those I need to compile with sbt. The structure is like this:
main_project
- sub_project1
- sub_project2
- sub_project3
Of course, they have the correct directory hierarchy (src-main-scala....). How do I compile all of them and each of them in particular?
Typically, if a key has no associated value in a more-specific scope, sbt will try to get a value from a more general scope, such as the ThisBuild scope. This feature allows you to set a value once in a more general scope, allowing multiple more-specific scopes to inherit the value.
Library dependencies can be added in two ways: unmanaged dependencies are jars dropped into the lib directory. managed dependencies are configured in the build definition and downloaded automatically from repositories.
sbt is a popular tool for compiling, running, and testing Scala projects of any size. Using a build tool such as sbt (or Maven/Gradle) becomes essential once you create projects with dependencies or more than one code file.
You can use both managed and unmanaged dependencies in your SBT projects. If you have JAR files (unmanaged dependencies) that you want to use in your project, simply copy them to the lib folder in the root directory of your SBT project, and SBT will find them automatically.
See Navigating projects interactively:
At the sbt interactive prompt, type
projects
to list your projects andproject <projectname>
to select a current project. When you run a task likecompile
, it runs on the current project. So you don't necessarily have to compile the root project, you could compile only a subproject.
You can use aggregate to compile them all.
Because the selected answer's linked documentation has changed, the answer isn't so clear anymore.
In the build.sbt
of OP's main_project
, to compile them together they will have to define an aggregate
, as the new(er) documentation links to:
lazy val root = (project in file("."))
.aggregate(util, core)
lazy val util = (project in file("util"))
lazy val core = (project in file("core"))
And then running an sbt compile
in the root project's directory will compile them all.
However, if you wish to compile one at a time, you can navigate your cmd line/terminal to the root project ( main_project
here) and then run the following command:
user:main_project$: sbt <project name> / compile
to use the poster's example:
user:main_project$: sbt sub_project1 / compile
(if you are in the SBT terminal, then you can omit sbt
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With