How to set up a dependency between two Scala.js cross-projects in a multi-module build?

我的梦境 提交于 2019-12-08 10:10:17

问题


Say I have two sub-projects, lib1 and lib2 with build.sbts that look like this:

lazy val libX = crossProject.in(file(".")).settings(
  ... // a bunch of settings
).jvmSettings(
  ... // a bunch of settings  
).jsSettings(
  ... // a bunch of settings
)

lazy val libXJVM = apiClient.jvm
lazy val libXJS = apiClient.js

I need to use them in another large multi-module project so that lib2 depends on lib1.

If I try this in the main build.sbt:

lazy val lib1 = crossProject.in(file("lib1"))

lazy val lib2 = crossProject.in(file("lib2")).dependsOn(lib1)

lazy val lib1JVM = lib1.jvm
...

then the project dependency seems to work but the settings from the libraries internal build.sbt files (e.g. libraryDependencies) are completely ignored and the build fails.

If I try this instead:

lazy val lib1JS = project.in(file("lib1"))
lazy val lib2JS = project.in(file("lib2")).dependsOn(lib1JS)

dependsOn is seemingly ignored and lib2 won't compile because it can't import types from lib1.

Is there any way to make this work without duplicating the crossProject settings in the main build file?


回答1:


If I understand correctly, you are trying to dependsOn (cross) projects that are defined in a completely separate build?

If that is the case, what you need are ProjectRef. There is no direct of CrossProjectRef, so you need to manually use ProjectRefs for the JVM and JS parts. It would look something like:

lazy val lib1JVM = ProjectRef(file("path/to/other/build", "lib1JVM")
lazy val lib1JS = ProjectRef(file("path/to/other/build", "lib1JS")

which you can then depend on with

lazy val myProject = crossProject
  .jvmConfigure(_.dependsOn(lib1JVM))
  .jsConfigure(_.dependsOn(lib1JS))

Note that I do not quite understand what you are trying to do with the lazy val lib2 = crossProject.in(file("lib2")).dependsOn(lib1) part of your question. If lib2 should depend on lib1, that dependency should already have been declared in the build of lib2. In your larger multi-module build that reuses lib1 and lib2, it is too late to add dependencies to lib2 which comes from another build.



来源:https://stackoverflow.com/questions/47658583/how-to-set-up-a-dependency-between-two-scala-js-cross-projects-in-a-multi-module

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!