sbt:依赖项目不先编译

时间:2021-05-10 20:32:50

标签: scala sbt

在我的build.sbt(没什么特别的)....

val common: Project =
  project
    .in(file("common"))
    .enablePlugins(...)
    .settings(libraryDependencies ++= ...)

val root =
project
      .in(file("."))
      .enablePlugins(...)
      .dependsOn(common)
      .aggregate(
        common,
        ....
      )
      .settings(...)

问题

common 不会在 root 之前编译,因此编译失败并抱怨找不到这些类(共同)

仅供参考

  • 在搜索有关此问题的一些信息(谷歌、文档、github 问题等)时,我尝试了很多我遇到的事情。没有运气。
  • sbt v1.4.9(播放项目 sbt-play v2.7.9)
  • build.sbt 比您在上面看到的要大得多(依赖项、任务等)。否则,我不认为它有什么特别或棘手的地方。

非常感谢帮助!

2 个答案:

答案 0 :(得分:2)

为了避免初始化问题,尝试将项目声明为惰性 vals

String text = "Win Win Loss Draw Hello";
String[] split = text.split(" ");

// To maintain unique value for each word of input string 
Map<String, Integer> = new HashMap<>();
int counter = 0;
for(String ele:split)
  if(!map.containsKey(ele))
    map.put(ele, ++counter)
 
// Getting unique value for each word and assigining in array
int[] array=new int[split.length];
for(int i=0; i<split.length;i++)
  array[i] = map.get(split[i]);

而不是严格的 vals

lazy val common = ...
lazy val root = ...

作为旁注,使用 val common = ... val root = ... 在子项目之间建立排序,而不是 dependsOn,因为 aggregate 不会修改类路径。

答案 1 :(得分:1)

我同意 Mario Galic 使用 strings <- c("DOG", "CAT", "BALL") string length output DOG 3 D, O, G, DO, DG, OG, DOG CAT 3 C, A, T, CA, CT, AT, CAT BALL 4 B, A, L, BA, BL, BAL 。事实上,我建议在 lazy val 中始终使用 lazy val

如果存在循环,例如 build.sbt 引用回 common,您可以使用的一种技巧是使用 root,例如 LocalProject("project name")

LocalProject("root")