How to get Intellij to use SBT scala dependencies

I am trying to understand how an idea will recognize trigger dependencies when using SBT. When I use gen-idea sbt plugin gen, you are expected to download all the necessary dependencies that will be placed in my ~ / .ivy / directory. How can these depilations be used?

EDIT: One thing I noticed is if I create a new idea project instead of a simple module, does this work? Any idea why this would be? I would like to have several sbt modules in one project.

+4
source share
2 answers

The sbt-idea module works with the multi-module sbt project. We used it from a place somewhere around sbt-0.10.0 and are currently located in sbt-0.11.2. It looks like you have the dependent part of the build file configured normally, so here is an example of how we do the project setup from the full Build.scala specification file:

object Vcaf extends Build { import Resolvers._ import Dependencies._ import BuildSettings._ lazy val vcafDb = Project( id = "vcaf-db", base = file("./vcaf-db"), dependencies = Seq(), settings = buildSettings ++ /* proguard */ SbtOneJar.oneJarSettings ++ Seq(libraryDependencies := dbDeps, resolvers := cseResolvers) ) lazy val vcaf = Project( "vcaf", file("."), dependencies = Seq(vcafDb), aggregate = Seq(vcafDb), settings = buildSettings ++ Seq(libraryDependencies := vcafDeps, resolvers := cseResolvers) ++ webSettings ) } 

In this example, the vcaf-db project is located in a folder in the vcaf project folder. The vcaf-db project does not have its own build.sbt or Build.scala file. You will notice that we indicate library dependencies for each project, which may or may not be your missing link.

As mentioned in ChrisJamesC, you need to “reboot” from SBT (or exit sbt and return) to get changes to the assembly definition. After reloading the project, you can make "gen-idea no-classifiers no-sbt-classifiers" and get the intellij project, which has the main project, modules and access to the library, as defined in the assembly file.

Hope this helps!

+3
source

If you need several SBT modules in one IDEA project, you can use sbt multi- project assemblies (aka subprojects). Just create a master project that references the modules as sub-projects, and then run gen-idea on the host computer. To indicate dependencies between modules, you should use Build.scala (not build.sbt), as in jxstanford's answer, or like this:

 lazy val foo = Project(id = "foo", base = file("foo")) lazy val bar = Project(id = "bar", base = file("bar")) dependsOn(foo) 

One level of subprojects works fine (with the correct reflections in the resulting IDEA project), but nested subprojects don't seem to work. In addition, it seems that the sbt limitation is that subprojects should live in subdirectories of the main project (ie file("../foo") not allowed).

See also How to manage multiple interdependent modules using SBT and IntelliJ IDEA? .

0
source

Source: https://habr.com/ru/post/1393550/


All Articles