仅使用sbt使用Gatling测试构建jar文件

时间:2019-01-16 18:45:07

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

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

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

我玩过sbt assembly,但似乎它在jar文件中打包了很多东西,我想不出如何限制它来避免像加特林这样的依赖。

我的总体项目结构类似于this回购。仓库中没有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的结果是,我仍然可以看到很多库,包括其中的加特林库。

1 个答案:

答案 0 :(得分:2)

是的,您是对的。似乎可以打包的组装插件。

您可以执行以下操作:

  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