0

I'm new to sbt and I've been trying to set up a multi-project with it but to no avail.
I've searched and came up with relevant info but was unable to set things up so that it will work.

Here's the structure that I have:

  • Shared project
  • ProjectOne
  • ProjectTwo

Each project has it's own build.sbt at it's root.
ProjectOne and ProjectTwo are "real" projects while the Shared one just contains utils that both of the other projects need, think of it as a library that they both use.
The "real" projects don't depend on each other.

Here's the latest build.sbt I have in ProjectOne:

name := "project-one"
version := "1.0"
scalaVersion := "2.11.8"

lazy val projectone = (project in file(".")).aggregate(shared)
lazy val shared = RootProject(file("../Shared"))

This works only in that I can see the shared project in my SBT projects view in IntelliJ:

  • projectone (root)
  • projectone-build
  • shared
  • shared-build

But when I try to use classes from shared intellij can't find it and asks me to

Add dependency on module 'Shared'

If I choose that then it's fine, but if I change the build.sbt file then this dependency goes away.
Also, when I try to run the project using typesafe-activator it fails to find the classes in the shared project.

So the question is how to add the dependency on Shared in the other projects?
Also, does the answer change if Shared isn't a sbt project? I might remove the need to use sbt with the shared module.

Thanks

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299
  • Since its unanswered, I'll offer my half-baked knowledge: As far as I know sbt and intellij don't know each other. You probably need an sbt intellij plugin but that will likely only fire sbt commands from Intellij. I'd say- use sbt command line because anything complex is best handled in sbt. Is thereany reason why you use RootProject for one project and project in file for second? Use project in file fr bth. Here's the sbt documentation: Its long but deals with all basic concepts. http://www.scala-sbt.org/documentation.html. Anything complex still requires spending time (in my experience) – 0fnt Jul 07 '16 at 04:12
  • Why do you share IntelliJ? Both projects are independent, no? In which case you should use two instances of IntelliJ- one for ProjectOne and other for ProjectTwo. – 0fnt Jul 07 '16 at 04:13
  • @0fnt It's not a matter of how I open the projects (in one `idea` or two), but how to compile the projects. Since in one project I use the source in the other, I need the sbt to be aware of that. It seems to me that `idea` works well with sbt, at least that's the case with a play! project that I have. The documentation isn't very helpful, I went all over it looking for an answer, and what I'm looking for isn't complex, it's pretty trivial and took me a minute to do with gradle for example. – Nitzan Tomer Jul 07 '16 at 07:27
  • Maybe trying using 'project in file' for both projects (as I pointed in my first comment if you missed the notification for that) – 0fnt Jul 07 '16 at 14:07
  • I didn't miss it, but I don't understand what you mean by it – Nitzan Tomer Jul 07 '16 at 14:13
  • You use RootProject for one project and 'project in file' for other. Try using the same constructor – 0fnt Jul 07 '16 at 15:49
  • Isn't that what I did? `shared` uses `RootProject` and `projectone` uses `project in file` – Nitzan Tomer Jul 07 '16 at 15:52

0 Answers0