在Intellij中构建交叉构建sbt项目

时间:2018-12-11 19:17:37

标签: scala intellij-idea sbt intellij-17 scala-version-cross-build

我有一个sbt项目,其中三个模块A,B,Common其中

  • A与2.11.12的scala版本兼容,并取决于Common
  • B与2.12.7的scala版本兼容,并取决于Common
  • Common可以与2.11.12和2.12.7版本交叉编译

为此,我创建了一个$!d,如下所示:

build.sbt

通过提供import sbt._ val scalaL = "2.11.12" val scalaH = "2.12.7" lazy val common = (project in file("common")) .settings(crossScalaVersions := Seq(scalaH, scalaL)) lazy val A = (project in file("A")) .settings(scalaVersion := scalaL) .dependsOn(common) lazy val B = (project in file("B")) .settings(scalaVersion := scalaH) .dependsOn(common) lazy val root = (project in file(".")) .aggregate(common, B, A) .settings(crossScalaVersions := List()) 前缀,我可以从sbt shell updatecompile进行此项目。

但是当我尝试使用sbt项目刷新选项在Idea Intellij Ultimate 2017.3版本中构建项目时,它因以下错误而中断:

+

从该错误中可以明显看出,它在更新A时无法解决Common模块的2.11依赖性。如果我从外壳程序运行Error while importing sbt project: ;reload; set _root_.org.jetbrains.sbt.StructureKeys.sbtStructureOptions in Global := "download resolveClassifiers" ;*/*:dumpStructureTo /tmp/sbt-structure1.xml; session clear-all [info] Loading settings for project global-plugins from idea.sbt ... [info] Loading global plugins from /home/bala/.sbt/1.0/plugins [info] Loading project definition from /home/bala/ether-streaming/cross2/project [info] Loading settings for project root from build.sbt ... [warn] Discarding 1 session setting. Use 'session save' to persist session settings. [info] Set current project to root (in build file:/home/bala/ether-streaming/cross2/) [info] Defining Global / sbtStructureOptions [info] The new value will be used by Global / ssOptions [info] Reapplying settings... [info] Set current project to root (in build file:/home/bala/ether-streaming/cross2/) [info] Updating A... [warn] module not found: common#common_2.11;0.1.0-SNAPSHOT [warn] ==== local: tried [warn] /home/bala/.ivy2/local/common/common_2.11/0.1.0-SNAPSHOT/ivys/ivy.xml [warn] ==== public: tried [warn] https://repo1.maven.org/maven2/common/common_2.11/0.1.0-SNAPSHOT/common_2.11-0.1.0-SNAPSHOT.pom [warn] ==== local-preloaded-ivy: tried [warn] /home/bala/.sbt/preloaded/common/common_2.11/0.1.0-SNAPSHOT/ivys/ivy.xml [warn] ==== local-preloaded: tried [warn] file:////home/bala/.sbt/preloaded/common/common_2.11/0.1.0-SNAPSHOT/common_2.11-0.1.0-SNAPSHOT.pom [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] :: UNRESOLVED DEPENDENCIES :: [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] :: common#common_2.11;0.1.0-SNAPSHOT: not found [warn] :::::::::::::::::::::::::::::::::::::::::::::: [warn] [warn] Note: Unresolved dependencies path: [warn] common:common_2.11:0.1.0-SNAPSHOT [warn] +- a:a_2.11:0.1.0-SNAPSHOT [error] sbt.librarymanagement.ResolveException: unresolved dependency: common#common_2.11;0.1.0-SNAPSHOT: not found [error] at sbt.internal.librarymanagement.IvyActions$.resolveAndRetrieve(IvyActions.scala:332) [error] at sbt.internal.librarymanagement.IvyActions$.$anonfun$updateEither$1(IvyActions.scala:208) [error] at sbt.internal.librarymanagement.IvySbt$Module.$anonfun$withModule$1(Ivy.scala:239) [error] at sbt.internal.librarymanagement.IvySbt.$anonfun$withIvy$1(Ivy.scala:204) [error] at sbt.internal.librarymanagement.IvySbt.sbt$internal$librarymanagement$IvySbt$$action$1(Ivy.scala:70) [error] at sbt.internal.librarymanagement.IvySbt$$anon$3.call(Ivy.scala:77) [error] at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:93) [error] at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:78) [error] at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:97) [error] at xsbt.boot.Using$.withResource(Using.scala:10) [error] at xsbt.boot.Using$.apply(Using.scala:9) [error] at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58) [error] at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48) [error] at xsbt.boot.Locks$.apply0(Locks.scala:31) [error] at xsbt.boot.Locks$.apply(Locks.scala:28) [error] at sbt.internal.librarymanagement.IvySbt.withDefaultLogger(Ivy.scala:77) [error] at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:199) [error] at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:196) [error] at sbt.internal.librarymanagement.IvySbt$Module.withModule(Ivy.scala:238) [error] at sbt.internal.librarymanagement.IvyActions$.updateEither(IvyActions.scala:193) [error] at sbt.librarymanagement.ivy.IvyDependencyResolution.update(IvyDependencyResolution.scala:20) [error] at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:56) [error] at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:45) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:93) [error] at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:68) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$19(LibraryManagement.scala:106) [error] at scala.util.control.Exception$Catch.apply(Exception.scala:224) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:106) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:89) [error] at sbt.util.Tracked$.$anonfun$inputChanged$1(Tracked.scala:149) [error] at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:120) [error] at sbt.Classpaths$.$anonfun$updateTask$5(Defaults.scala:2561) [error] at scala.Function1.$anonfun$compose$1(Function1.scala:44) [error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40) [error] at sbt.std.Transform$$anon$4.work(System.scala:67) [error] at sbt.Execute.$anonfun$submit$2(Execute.scala:269) [error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16) [error] at sbt.Execute.work(Execute.scala:278) [error] at sbt.Execute.$anonfun$submit$1(Execute.scala:269) [error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178) [error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:37) [error] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [error] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [error] at java.lang.Thread.run(Thread.java:748) [error] sbt.librarymanagement.ResolveException: unresolved dependency: common#common_2.11;0.1.0-SNAPSHOT: not found [error] at sbt.internal.librarymanagement.IvyActions$.resolveAndRetrieve(IvyActions.scala:332) [error] at sbt.internal.librarymanagement.IvyActions$.$anonfun$updateEither$1(IvyActions.scala:208) [error] at sbt.internal.librarymanagement.IvySbt$Module.$anonfun$withModule$1(Ivy.scala:239) [error] at sbt.internal.librarymanagement.IvySbt.$anonfun$withIvy$1(Ivy.scala:204) [error] at sbt.internal.librarymanagement.IvySbt.sbt$internal$librarymanagement$IvySbt$$action$1(Ivy.scala:70) [error] at sbt.internal.librarymanagement.IvySbt$$anon$3.call(Ivy.scala:77) [error] at xsbt.boot.Locks$GlobalLock.withChannel$1(Locks.scala:93) [error] at xsbt.boot.Locks$GlobalLock.xsbt$boot$Locks$GlobalLock$$withChannelRetries$1(Locks.scala:78) [error] at xsbt.boot.Locks$GlobalLock$$anonfun$withFileLock$1.apply(Locks.scala:97) [error] at xsbt.boot.Using$.withResource(Using.scala:10) [error] at xsbt.boot.Using$.apply(Using.scala:9) [error] at xsbt.boot.Locks$GlobalLock.ignoringDeadlockAvoided(Locks.scala:58) [error] at xsbt.boot.Locks$GlobalLock.withLock(Locks.scala:48) [error] at xsbt.boot.Locks$.apply0(Locks.scala:31) [error] at xsbt.boot.Locks$.apply(Locks.scala:28) [error] at sbt.internal.librarymanagement.IvySbt.withDefaultLogger(Ivy.scala:77) [error] at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:199) [error] at sbt.internal.librarymanagement.IvySbt.withIvy(Ivy.scala:196) [error] at sbt.internal.librarymanagement.IvySbt$Module.withModule(Ivy.scala:238) [error] at sbt.internal.librarymanagement.IvyActions$.updateEither(IvyActions.scala:193) [error] at sbt.librarymanagement.ivy.IvyDependencyResolution.update(IvyDependencyResolution.scala:20) [error] at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:56) [error] at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:45) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:93) [error] at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:68) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$19(LibraryManagement.scala:106) [error] at scala.util.control.Exception$Catch.apply(Exception.scala:224) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:106) [error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:89) [error] at sbt.util.Tracked$.$anonfun$inputChanged$1(Tracked.scala:149) [error] at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:120) [error] at sbt.Classpaths$.$anonfun$updateTask$5(Defaults.scala:2561) [error] at scala.Function1.$anonfun$compose$1(Function1.scala:44) [error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40) [error] at sbt.std.Transform$$anon$4.work(System.scala:67) [error] at sbt.Execute.$anonfun$submit$2(Execute.scala:269) [error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16) [error] at sbt.Execute.work(Execute.scala:278) [error] at sbt.Execute.$anonfun$submit$1(Execute.scala:269) [error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178) [error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:37) [error] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [error] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [error] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [error] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [error] at java.lang.Thread.run(Thread.java:748) [error] (A / update) sbt.librarymanagement.ResolveException: unresolved dependency: common#common_2.11;0.1.0-SNAPSHOT: not found [error] (A / ssExtractDependencies) sbt.librarymanagement.ResolveException: unresolved dependency: common#common_2.11;0.1.0-SNAPSHOT: not found [error] Total time: 1 s, completed 12 Dec, 2018 12:24:28 AM 而不是update,也会发生类似的错误。 / p>

如何在Intellij中进行交叉构建?还是Intellij中有任何现有选项来支持跨版本?

1 个答案:

答案 0 :(得分:0)

我认为您的布局有些不寻常,但是经过一些试验,我能够提出一些我认为可以接受的东西。它导入到IDE中,语法高亮显示在所有模块中,IDE甚至正确地在A / B部分中提供2.11 / 2.12特定的补全,并根据需要构建模块。

val scalaL = "2.11.12"
val scalaH = "2.12.7"

lazy val common = (project in file("common"))
  .settings(crossScalaVersions := Seq(scalaH, scalaL))

lazy val A = (project in file("A"))
  .settings(scalaVersion := scalaL)
  .dependsOn(common)

lazy val B = (project in file("B"))
  .settings(scalaVersion := scalaH)
  .dependsOn(common)

lazy val rootA = (project in file("rootA"))
  .aggregate(common, A)
  .settings(scalaVersion := scalaL)

lazy val rootB = (project in file("rootB"))
  .aggregate(common, B)
  .settings(scalaVersion := scalaH)

lazy val root = (project in file(".")).aggregate(rootA)