wykopowiedz1
wykopowiedz1

Reputation: 103

Create target directory outside project directory with sbt

The structure of my project is:

└───current-working-dir
    ├───my-project
        ├───src

When I run sbt compile in current-working-dir where .sbt file looks like:

lazy val root = (project in file("my-project"))
  .settings(
    name := "my-project",
    settings,
    libraryDependencies ++= commonDependencies
  )

then it generates target in the project directory:

└───current-working-dir
    ├───my-project
        ├───src
        ├───target

Is it possible to make sbt to create target outside the project directory? For instance:

└───current-working-dir
    ├───my-project
        ├───src
    ├───target

or

└───current-working-dir
    ├───my-project
        ├───src
    ├───my-project-compilation
        ├───target

Upvotes: 1

Views: 376

Answers (2)

Dmytro Mitin
Dmytro Mitin

Reputation: 51648

Actually, I guess correct is

lazy val root = (project in file("my-project"))
  .settings(
    name := "my-project",
    settings,
    libraryDependencies ++= commonDependencies,
    target := baseDirectory.value / ".." / "my-project-compilation" / "target"
  )

You can check that if you place file as current-working-dir/my-project/src/main/scala/App.scala then compiled class appears as current-working-dir/my-project-compilation/target/scala-2.13/classes/App.class.

Upvotes: 1

Mario Galic
Mario Galic

Reputation: 48400

target setting controls where files are generated. Here is an example how to change it

target := baseDirectory.value / "my-project-compilation" / "target"

Upvotes: 2

Related Questions