[英]How to set up a dependency between two Scala.js cross-projects in a multi-module build?
Say I have two sub-projects, lib1
and lib2
with build.sbt
s that look like this: 假设我有两个子项目lib1
和lib2
, build.sbt
带有build.sbt
,如下所示:
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
. 我需要在另一个大型多模块项目中使用它们,以便lib2
依赖lib1
。
If I try this in the main build.sbt
: 如果我在主要build.sbt
尝试此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 (eg libraryDependencies
) are completely ignored and the build fails. 那么项目依赖项似乎可以正常工作,但是库内部build.sbt
文件中的设置(例如libraryDependencies
)将被完全忽略,并且构建失败。
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. 表面上, dependsOn
似乎被忽略,并且lib2无法编译,因为它无法从lib1导入类型。
Is there any way to make this work without duplicating the crossProject settings in the main build file? 有没有什么方法可以做到这一点而无需在主构建文件中复制crossProject设置?
If I understand correctly, you are trying to dependsOn
(cross) projects that are defined in a completely separate build? 如果我理解正确,那么您正在尝试dependsOn
完全独立的构建中定义的(跨)项目吗?
If that is the case, what you need are ProjectRef
. 在这种情况下,您需要的是ProjectRef
。 There is no direct of CrossProjectRef
, so you need to manually use ProjectRef
s for the JVM and JS parts. CrossProjectRef
没有直接的CrossProjectRef
,因此您需要为JVM和JS部分手动使用ProjectRef
。 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. 请注意,我不太了解您要如何使用lazy val lib2 = crossProject.in(file("lib2")).dependsOn(lib1)
部分。 If lib2
should depend on lib1
, that dependency should already have been declared in the build of lib2
. 如果lib2
应该依赖lib1
,则该依赖关系应该已经在lib2
的构建中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. 在更大的lib1
和lib2
多模块构建中,将依赖关系添加到另一个构建的lib2
为时已晚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.