【问题标题】:Build jar file with Gatling tests only with sbt仅使用 sbt 构建带有 Gatling 测试的 jar 文件
【发布时间】:2019-06-10 21:57:50
【问题描述】:

我正在尝试使用 Gatling 测试构建 jar 文件,最终我需要将其传递给 Taurus 但似乎我的 jar 太胖了,并且与 Taurus 的内部库发生冲突。

所以我认为我只需要打包我的测试文件而不需要其他依赖项。

我玩过sbt assembly,但它似乎将“太多”打包到 jar 文件中,我不知道如何限制它以避免像加特林本身这样的依赖关系。

我的一般项目结构类似于this repo。我在 repo 中没有 main 文件夹(我需要拥有它吗?)

sbt native packager 可以帮我吗?

更新

Here 是我用来测试组装的仓库

我想要包含的测试文件位于src/it

我的build.sbt(不确定在这种情况下是否都有意义)

enablePlugins(GatlingPlugin)
enablePlugins(AssemblyPlugin)

scalaVersion := "2.12.8"
// This forbids including Scala related libraries into the dependency
autoScalaLibrary := false

// dependencies for Gatling
libraryDependencies += "io.gatling.highcharts" % "gatling-charts-highcharts" % "3.0.2" % Provided
libraryDependencies += "io.gatling"            % "gatling-test-framework"    % "3.0.2" % Provided

assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false)

// make '~' work (again :))
watchSources += baseDirectory.value / "src" / "it"

// configure the assembly
fullClasspath in assembly := (fullClasspath in GatlingIt).value
mainClass in assembly := Some("io.gatling.app.Gatling")
assemblyMergeStrategy in assembly := {
  case path if path.endsWith("io.netty.versions.properties") => MergeStrategy.first
  case path => {
    val currentStrategy = (assemblyMergeStrategy in assembly).value
    currentStrategy(path)
  }
}
test in assembly := {}

我做sbt assembly 的结果是我仍然可以看到很多图书馆——包括加特林的图书馆。

【问题讨论】:

    标签: scala sbt gatling sbt-assembly sbt-native-packager


    【解决方案1】:

    是的,你是对的。汇编插件好像打包的太多了。

    您可以执行以下操作:

    1. 如果您的执行环境已安装,则排除 scala 库。 您可以将以下代码添加到 build.sbt
    assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false)
    
    1. 将执行环境中已安装的依赖项设置为已提供。例如
    libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.2.1" % Provided
    

    【讨论】:

    • 感谢@gccodec 的回复。我在 build.sbt 中设置了libraryDependencies += "io.gatling.highcharts" % "gatling-charts-highcharts" % "3.0.2" % "test,it" % Provided,但现在出现错误:java.lang.IllegalArgumentException: requirement failed: Configurations already specified for module io.gatling:gatling-test-framework:3.0.2:test,it
    • 你能添加你的 build.sbt 文件吗?在这种情况下,问题是您已经指定了“test,it”之类的配置。您需要将“test,it”更改为提供。例如:` libraryDependencies += "io.gatling.highcharts" % "gatling-charts-highcharts" % "3.0.2" % Provided `
    • 用 build.sbt 文件更新了我的帖子
    • 好的,伙计。我有点困惑。 Gatling 仅适用于测试范围,因此您需要将范围类型从提供更改为测试。我尝试用一​​个简单的项目复制你的 build.sbt,在组装阶段我只有我的 MainApp scala 类在文件 jar 上,显然是 META-INF 文件。
    猜你喜欢
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-07
    • 2014-12-13
    • 2011-09-15
    • 1970-01-01
    • 2016-01-28
    • 2021-01-21
    相关资源
    最近更新 更多