Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
moglideveloper opened this issue Jul 5, 2022 · 0 comments

Comments

@moglideveloper
Copy link

moglideveloper commented Jul 5, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant