sbt 着色两个版本的依赖
sbt shading two versions of a dependency
当我 运行 我的测试时,我看到以下错误:
Exception: java.lang.NoSuchMethodError: fs2.Stream$.bracket(Ljava/lang/Object;Lscala/Function1;Lscala/Function1;)Lfs2/internal/FreeC;
我首先确保 explicitly declaring transitive dependencies and by removing unused dependencies 清理了我的构建文件以生成以下内容 build.sbt:
scalaVersion := "2.12.7"
organization := "com.example "
lazy val lambdas = (project in file("."))
.settings(
libraryDependencies += "org.typelevel" %% "cats-core" % "1.4.0",
libraryDependencies += "org.typelevel" %% "cats-effect" % "1.0.0",
libraryDependencies += "io.circe" %% "circe-core" % "0.10.0",
libraryDependencies += "io.circe" %% "circe-generic" % "0.10.0",
libraryDependencies += "io.circe" %% "circe-parser" % "0.10.0",
libraryDependencies += "io.circe" %% "circe-fs2" % "0.10.0",
libraryDependencies += "co.fs2" %% "fs2-core" % "1.0.0",
libraryDependencies += "co.fs2" %% "fs2-io" % "0.10.0",
libraryDependencies += "org.http4s" %% "http4s-circe" % "0.18.0",
libraryDependencies += "org.http4s" %% "http4s-client" % "0.18.0",
libraryDependencies += "org.http4s" %% "http4s-core" % "0.18.0",
libraryDependencies += "com.chuusai" %% "shapeless" % "2.3.3",
libraryDependencies += "com.amazonaws" % "aws-lambda-java-core" % "1.2.0",
libraryDependencies += "com.amazonaws" % "aws-java-sdk-core" % "1.11.422",
libraryDependencies += "com.amazonaws" % "aws-java-sdk-s3" % "1.11.422",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test",
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.0" % "test",
libraryDependencies += "io.findify" %% "s3mock" % "0.2.4" % "test"
)
一切都编译通过,我的两个测试之一通过了。另一个失败并出现上述错误。这是 sbt evicted 的输出:
[warn] Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
[warn] * co.fs2:fs2-core_2.12:1.0.0 is selected over 0.10.0
[warn] +- io.circe:circe-fs2_2.12:0.10.0 (depends on 1.0.0)
[warn] +- com.example:lambdas_2.12:0.1.0-SNAPSHOT (depends on 1.0.0)
[warn] +- co.fs2:fs2-scodec_2.12:0.10.0 (depends on 0.10.0)
[warn] +- org.http4s:jawn-fs2_2.12:0.12.0 (depends on 0.10.0)
[warn] +- co.fs2:fs2-io_2.12:0.10.0 (depends on 0.10.0)
[warn] * org.typelevel:cats-effect_2.12:1.0.0 is selected over 0.8
[warn] +- co.fs2:fs2-core_2.12:1.0.0 (depends on 1.0.0)
[warn] +- com.example:lambdas_2.12:0.1.0-SNAPSHOT (depends on 1.0.0)
[warn] +- org.http4s:http4s-core_2.12:0.18.0 (depends on 0.8)
[warn] * org.typelevel:cats-core_2.12:1.4.0 is selected over {1.0.1, 1.3.1}
[warn] +- io.circe:circe-core_2.12:0.10.0 () (depends on 1.4.0)
[warn] +- co.fs2:fs2-core_2.12:1.0.0 (depends on 1.4.0)
[warn] +- org.typelevel:cats-effect_2.12:1.0.0 (depends on 1.3.1)
[warn] +- com.example:lambdas_2.12:0.1.0-SNAPSHOT (depends on 1.3.1)
[warn] +- org.http4s:http4s-core_2.12:0.18.0 (depends on 1.0.1)
[warn] * io.circe:circe-jawn_2.12:0.10.0 is selected over 0.9.1
[warn] +- io.circe:circe-parser_2.12:0.10.0 () (depends on 0.10.0)
[warn] +- io.circe:circe-fs2_2.12:0.10.0 (depends on 0.10.0)
[warn] +- org.http4s:http4s-circe_2.12:0.18.0 (depends on 0.9.1)
[warn] * org.spire-math:jawn-parser_2.12:0.13.0 is selected over 0.11.0
[warn] +- io.circe:circe-jawn_2.12:0.10.0 () (depends on 0.13.0)
[warn] +- org.http4s:jawn-fs2_2.12:0.12.0 (depends on 0.11.0)
[warn] Run 'evicted' to see detailed eviction warnings
[info] Here are other depedency conflicts that were resolved:
[info] * commons-logging:commons-logging:1.1.3 is selected over 1.2
[info] +- com.amazonaws:aws-java-sdk-core:1.11.422 (depends on 1.1.3)
[info] +- org.apache.httpcomponents:httpclient:4.5.5 (depends on 1.2)
[success] Total time: 2 s, completed Nov 28, 2018 12:56:33 PM
从使用 sbt-dependency-graph 来看,我似乎合法地需要两个版本的 fs2-core:1.0.0
和 0.10.0
。
这是我尝试使用 sbt-assembly shading 通过在需要它的 http4s 库中重命名旧版本的 fs2 来处理驱逐。这个构建文件实际上没有编译任何东西,所以我猜我的设置方式存在多个问题。
//build properties
//sbt.version=1.1.2
//assembly.sbt
//addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.8")
scalaVersion := "2.12.7"
organization := "com.example"
lazy val fatJar = project
.enablePlugins(AssemblyPlugin)
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "1.4.0",
"org.typelevel" %% "cats-effect" % "1.0.0",
"io.circe" %% "circe-core" % "0.10.0",
"io.circe" %% "circe-generic" % "0.10.0",
"io.circe" %% "circe-parser" % "0.10.0",
"io.circe" %% "circe-fs2" % "0.10.0",
"co.fs2" %% "fs2-core" % "1.0.0",
"co.fs2" %% "fs2-io" % "0.10.0",
"org.http4s" %% "http4s-circe" % "0.18.0",
"org.http4s" %% "http4s-client" % "0.18.0",
"org.http4s" %% "http4s-core" % "0.18.0",
"com.chuusai" %% "shapeless" % "2.3.3",
"com.amazonaws" % "aws-lambda-java-core" % "1.2.0",
"com.amazonaws" % "aws-java-sdk-core" % "1.11.422",
"com.amazonaws" % "aws-java-sdk-s3" % "1.11.422",
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"org.scalacheck" %% "scalacheck" % "1.14.0" % "test",
"io.findify" %% "s3mock" % "0.2.4" % "test"),
assemblyShadeRules in assembly ++= Seq(
ShadeRule.rename("co.fs2.**" -> "old_fs2.@1")
.inLibrary("org.http4s" %% "http4s-circe" % "0.18.0")
.inLibrary("org.http4s" %% "http4s-core" % "0.18.0")
)
)
lazy val kraken_shaded = (project in file("."))
.settings(
name := "kraken-shaded",
packageBin in Compile := (assembly in (fatJar, Compile)).value
我不是 http4s 和 fs2 方面的专家,但我相信 1.0.x
版本的fs2 引入重大变化。
而且,正如您所见 here,http4s 0.18.x
是针对 fs2 0.10.x
.
因此,我不相信你能让他们一起工作。
您可能会考虑为 http4s 着色 0.10.x
版本的 fs2 并使用 1.0.x
版本在您的项目中...
但是,我认为这是不可能的,除非你从不使用由 http4s 创建的 Stream 或者你传递 Stream 到 http4s - 这绝对不是它的工作方式。
不过,您可以使用 http4s 0.20.x
。
现在它是一个 里程碑,因此您可以期待在它变得稳定之前发生变化 - 但如果您不想降级到 fs2[,它现在可能会起作用=42=] 0.10.x
.
当我 运行 我的测试时,我看到以下错误:
Exception: java.lang.NoSuchMethodError: fs2.Stream$.bracket(Ljava/lang/Object;Lscala/Function1;Lscala/Function1;)Lfs2/internal/FreeC;
我首先确保 explicitly declaring transitive dependencies and by removing unused dependencies 清理了我的构建文件以生成以下内容 build.sbt:
scalaVersion := "2.12.7"
organization := "com.example "
lazy val lambdas = (project in file("."))
.settings(
libraryDependencies += "org.typelevel" %% "cats-core" % "1.4.0",
libraryDependencies += "org.typelevel" %% "cats-effect" % "1.0.0",
libraryDependencies += "io.circe" %% "circe-core" % "0.10.0",
libraryDependencies += "io.circe" %% "circe-generic" % "0.10.0",
libraryDependencies += "io.circe" %% "circe-parser" % "0.10.0",
libraryDependencies += "io.circe" %% "circe-fs2" % "0.10.0",
libraryDependencies += "co.fs2" %% "fs2-core" % "1.0.0",
libraryDependencies += "co.fs2" %% "fs2-io" % "0.10.0",
libraryDependencies += "org.http4s" %% "http4s-circe" % "0.18.0",
libraryDependencies += "org.http4s" %% "http4s-client" % "0.18.0",
libraryDependencies += "org.http4s" %% "http4s-core" % "0.18.0",
libraryDependencies += "com.chuusai" %% "shapeless" % "2.3.3",
libraryDependencies += "com.amazonaws" % "aws-lambda-java-core" % "1.2.0",
libraryDependencies += "com.amazonaws" % "aws-java-sdk-core" % "1.11.422",
libraryDependencies += "com.amazonaws" % "aws-java-sdk-s3" % "1.11.422",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test",
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.0" % "test",
libraryDependencies += "io.findify" %% "s3mock" % "0.2.4" % "test"
)
一切都编译通过,我的两个测试之一通过了。另一个失败并出现上述错误。这是 sbt evicted 的输出:
[warn] Found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
[warn] * co.fs2:fs2-core_2.12:1.0.0 is selected over 0.10.0
[warn] +- io.circe:circe-fs2_2.12:0.10.0 (depends on 1.0.0)
[warn] +- com.example:lambdas_2.12:0.1.0-SNAPSHOT (depends on 1.0.0)
[warn] +- co.fs2:fs2-scodec_2.12:0.10.0 (depends on 0.10.0)
[warn] +- org.http4s:jawn-fs2_2.12:0.12.0 (depends on 0.10.0)
[warn] +- co.fs2:fs2-io_2.12:0.10.0 (depends on 0.10.0)
[warn] * org.typelevel:cats-effect_2.12:1.0.0 is selected over 0.8
[warn] +- co.fs2:fs2-core_2.12:1.0.0 (depends on 1.0.0)
[warn] +- com.example:lambdas_2.12:0.1.0-SNAPSHOT (depends on 1.0.0)
[warn] +- org.http4s:http4s-core_2.12:0.18.0 (depends on 0.8)
[warn] * org.typelevel:cats-core_2.12:1.4.0 is selected over {1.0.1, 1.3.1}
[warn] +- io.circe:circe-core_2.12:0.10.0 () (depends on 1.4.0)
[warn] +- co.fs2:fs2-core_2.12:1.0.0 (depends on 1.4.0)
[warn] +- org.typelevel:cats-effect_2.12:1.0.0 (depends on 1.3.1)
[warn] +- com.example:lambdas_2.12:0.1.0-SNAPSHOT (depends on 1.3.1)
[warn] +- org.http4s:http4s-core_2.12:0.18.0 (depends on 1.0.1)
[warn] * io.circe:circe-jawn_2.12:0.10.0 is selected over 0.9.1
[warn] +- io.circe:circe-parser_2.12:0.10.0 () (depends on 0.10.0)
[warn] +- io.circe:circe-fs2_2.12:0.10.0 (depends on 0.10.0)
[warn] +- org.http4s:http4s-circe_2.12:0.18.0 (depends on 0.9.1)
[warn] * org.spire-math:jawn-parser_2.12:0.13.0 is selected over 0.11.0
[warn] +- io.circe:circe-jawn_2.12:0.10.0 () (depends on 0.13.0)
[warn] +- org.http4s:jawn-fs2_2.12:0.12.0 (depends on 0.11.0)
[warn] Run 'evicted' to see detailed eviction warnings
[info] Here are other depedency conflicts that were resolved:
[info] * commons-logging:commons-logging:1.1.3 is selected over 1.2
[info] +- com.amazonaws:aws-java-sdk-core:1.11.422 (depends on 1.1.3)
[info] +- org.apache.httpcomponents:httpclient:4.5.5 (depends on 1.2)
[success] Total time: 2 s, completed Nov 28, 2018 12:56:33 PM
从使用 sbt-dependency-graph 来看,我似乎合法地需要两个版本的 fs2-core:1.0.0
和 0.10.0
。
这是我尝试使用 sbt-assembly shading 通过在需要它的 http4s 库中重命名旧版本的 fs2 来处理驱逐。这个构建文件实际上没有编译任何东西,所以我猜我的设置方式存在多个问题。
//build properties
//sbt.version=1.1.2
//assembly.sbt
//addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.8")
scalaVersion := "2.12.7"
organization := "com.example"
lazy val fatJar = project
.enablePlugins(AssemblyPlugin)
.settings(
libraryDependencies ++= Seq(
"org.typelevel" %% "cats-core" % "1.4.0",
"org.typelevel" %% "cats-effect" % "1.0.0",
"io.circe" %% "circe-core" % "0.10.0",
"io.circe" %% "circe-generic" % "0.10.0",
"io.circe" %% "circe-parser" % "0.10.0",
"io.circe" %% "circe-fs2" % "0.10.0",
"co.fs2" %% "fs2-core" % "1.0.0",
"co.fs2" %% "fs2-io" % "0.10.0",
"org.http4s" %% "http4s-circe" % "0.18.0",
"org.http4s" %% "http4s-client" % "0.18.0",
"org.http4s" %% "http4s-core" % "0.18.0",
"com.chuusai" %% "shapeless" % "2.3.3",
"com.amazonaws" % "aws-lambda-java-core" % "1.2.0",
"com.amazonaws" % "aws-java-sdk-core" % "1.11.422",
"com.amazonaws" % "aws-java-sdk-s3" % "1.11.422",
"org.scalatest" %% "scalatest" % "3.0.5" % "test",
"org.scalacheck" %% "scalacheck" % "1.14.0" % "test",
"io.findify" %% "s3mock" % "0.2.4" % "test"),
assemblyShadeRules in assembly ++= Seq(
ShadeRule.rename("co.fs2.**" -> "old_fs2.@1")
.inLibrary("org.http4s" %% "http4s-circe" % "0.18.0")
.inLibrary("org.http4s" %% "http4s-core" % "0.18.0")
)
)
lazy val kraken_shaded = (project in file("."))
.settings(
name := "kraken-shaded",
packageBin in Compile := (assembly in (fatJar, Compile)).value
我不是 http4s 和 fs2 方面的专家,但我相信 1.0.x
版本的fs2 引入重大变化。
而且,正如您所见 here,http4s 0.18.x
是针对 fs2 0.10.x
.
因此,我不相信你能让他们一起工作。
您可能会考虑为 http4s 着色 0.10.x
版本的 fs2 并使用 1.0.x
版本在您的项目中...
但是,我认为这是不可能的,除非你从不使用由 http4s 创建的 Stream 或者你传递 Stream 到 http4s - 这绝对不是它的工作方式。
不过,您可以使用 http4s 0.20.x
。
现在它是一个 里程碑,因此您可以期待在它变得稳定之前发生变化 - 但如果您不想降级到 fs2[,它现在可能会起作用=42=] 0.10.x
.