JetBrains / sbt-ide-settings

SBT plugin for tweaking various IDE settings
Apache License 2.0
62 stars 8 forks source link

sbt source directories with separate soutput directories to avoid class fqn conflicts #13

Open moglideveloper opened 2 years ago

moglideveloper commented 2 years ago

I am trying to keep multiple revisions of a file in different source directories. So, that they can be referenced quicky with the ongoing discussion.

We are using intellij. And the challenge is, we can not have multiple files with same fully qualified class name.

So, I was thinking to have multiple source directories with multiple output directories to avoid any clash of fqns.

And we are trying to achieve this with the help of build.sbt.

Note : We just need this setup for teaching and executing java files from intellij. We really not looking for building jar and other things. Also, I know that I can use git commits also for this, but I still want to try sbt approach.

Please find simplified project with simplified build.sbt.

I am able to assign different classDirectory for different source directories (see console output in screenshot), but intellij is not generating class in new class directories.

Please find below simplified build.sbt :-

name := "src-dirs"

lazy val Step1 = config("Step1") extend(Compile)
lazy val step1Settings: Seq[Setting[_]] =
  inConfig(Step1)(
    Seq(
      Step1 / target := (Compile / target).value.getParentFile / "src-target",
      Step1 / crossTarget := (Step1 / target).value / (Compile / crossTarget).value.name,
      Step1 / unmanagedSourceDirectories += (Compile / baseDirectory).value / "step1",
      Step1 / classDirectory := (Step1 / crossTarget).value / "step1"
    )
  )

lazy val Step2 = config("Step2") extend(Compile)
lazy val step2Settings: Seq[Setting[_]] =
  inConfig(Step1)(
    Seq(
      Step2 / target := (Compile / target).value.getParentFile / "src-target",
      Step2 / crossTarget := (Step2 / target).value / (Compile / crossTarget).value.name,
      Step2 / unmanagedSourceDirectories += (Compile / baseDirectory).value / "step2",
      Step2 / classDirectory := (Step2 / crossTarget).value / "step2"
    )
  )

val exampleProject = (project in file("."))
  .configs(Seq(Step1, Step2) : _*)
  .settings(step1Settings ++ step2Settings)

Simplified project can be accessed from below github url :-

https://github.com/moglideveloper/sbt-source-directories

image

Stackoverflow link :- https://stackoverflow.com/questions/72858786/sbt-source-directories-with-separate-soutput-directories-to-avoid-class-fqn-conf

Kindly suggest if sbt-ide-settings (or some other approach) can be used to resolve this.