简体   繁体   中英

SBT multi project in Intellij

Im trying to use a single Intellij IDEA window with multi projects (that are not related) imported. The problem that I'm facing is when I'm executing a sbt task , the task is not loaded in the right project directory.

This is what I did (all in the Intellij Idea window):

  1. Opened a root empty sbt project.
  2. In the sbt toolbar, I clicked the + and added 2 projects job-service and user-service (each was its own build.sbt file)
  3. Pressed Reimport All sbt projects just for fun
  4. Executed compile (from the sbt toolbar) for the user-service

The sbt shell opened, and started compiling the empty root project:

[info] Set current project to root (in build file:/Users/dima/git/root/)
[IJ]sbt:root> compile

what I've expected is

[info] Set current project to user-service (in build file:/Users/dima/git/user-service/)

And of course, the same for the second project job-service

Versions:

Idea version: Version: 2019.2 Build: 192.5728.98
SBT version = 0.13.18

I know the way to use a single build.sbt file with multi projects. But those projects are not related. each project has its own build.sbt file. I just want to use a single Idea window with multiple projects. and that the sbt toolbar could execute the tasks to the right project

Thanks!

EDIT :

This is the process to recreate what I'm facing:

  1. open project named root2
  2. Import another sbt project called learner
  3. Compile the learner project from the sbt toolbar!
  4. The Problem: sbt shell sets current project to root2

the same for publishLocal task. it sets the current project to root2 and publishes a root2 artifact. what should have been, is that the sbt would set the current project to learner

I have this problem on IntelliJ some time ago, but in that moment my project was not sbt related. That project contains two different applications in different programming languages, so they could not have a common build file.

But I've found a solution to solve this problem which was using IntelliJ Modules . These Modules will let you create different projects inside your current workspace.

You can access it in File -> Project Structure... -> Modules (In the left panel)

I think you can use this feature to accomplish your expected result. Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM