Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set settings for a subproject in sbt shell (without using project command)?

Tags:

scala

sbt

In sbt shell how do I set a setting for a subproject?

I know I can project subproject then set key := value, but I don't want to have to keep switching projects. Ideally something not too different from:

set key in subproject := value
like image 614
Dale Wijnand Avatar asked Jul 23 '14 08:07

Dale Wijnand


People also ask

What is ThisBuild in sbt?

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.

What does sbt clean do?

clean – delete all generated sources, compiled artifacts, intermediate products, and generally all build-produced files. reload – reload the build, to take into account changes to the sbt plugin and its transitive dependencies.


1 Answers

I think the problem is that you have defined your projects in build.sbt, and they seem not to be visible in the sbt console. At least in the current version of sbt - see this issue and this issue that were in fact fixed just a couple of days ago (!)

I have found two ways to overcome this limitation.

Use quotes around the project id

set version in "projectId" := "some-version"

Create a full build definition in project/Build.scala file

With the following build definition file build/Build.scala:

import sbt._
import Keys._

object Build extends Build {
  lazy val projectA, projectB = project
}

you should be fine to execute set version in projectA := "1.42-SNAPSHOT with the expected effect.

Additionally you could just have the build/Build.scala containing the project definition and rest of the configuration have in build.sbt for each submodule. It'd work perfectly fine with set.

like image 69
lpiepiora Avatar answered Sep 21 '22 02:09

lpiepiora