Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ: How do I override a dependency in SBT with a module imported from local source?

I have 2 projects, Project A and Project B. Project A is a Play2 App that depends on Project B (which is a client library.) Currently Project B is pulled from our artifactory with SBT. I would like to set up IntelliJ such that Project B is pulled from the project source on my computer, rather than from the artifactory that is specified in.

I have added Project B as a module of Project A and added Module B to the dependencies of Module A. I then ordered Module B to be at the very top of the dependency list. The static analysis of the code seems to be working fine, there's not compilation errors showing when I updated Project A's code to use a new method signature that I've updated in Project B. However, when I run the Play App I get a compilation error stating that the method signature is incorrect.

Is there a way to override the module used at runtime for SBT and the Play App?

like image 286
Segfault Avatar asked Oct 18 '22 18:10

Segfault


1 Answers

You can do this via sbt. In your build.sbt, for example:

val localDep = ProjectRef(file("/Users/me/projects/b"), "b")

dependsOn(localDep)

IntelliJ will import this dependency as a module. You should remove the library dependency however, to avoid conflicting classpaths.

Naturally, this makes the project hard to share unless other developers have the project in the same location. In that case, I would create a multi-project build instead, which is usually the best choice for tightly coupled projects with individual resulting artifacts.

Another option is a git project dependency:

val projectDep = ProjectRef(uri("git://github.com/me/b"),"b")
like image 101
Justin Kaeser Avatar answered Oct 21 '22 08:10

Justin Kaeser