Michal
Michal

Reputation: 3276

Build jar file with Gatling tests only with sbt

I'm trying to build jar file with Gatling tests which eventually I need to pass to Taurus but it seems that my jar is to fat and it clashes with internal libraries in Taurus.

So I think I need to pack only my test files and no other dependencies.

I played with sbt assembly but it seems that it packs 'to much' into the jar file and I can't figure out how to limit it to avoid dependencies like gatling itself.

My general project structure is similar to this repo. I don't have main folder in the repo (do I need to have it?)

Could sbt native packager help me here?

UPDATE

Here is repo which I use to test assembling

Test files that I want to include are in src/it

My build.sbt (not sure if all makes sense in this context)

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 := {}

The result when I do sbt assembly is that I still can see lots of libraries - including Gatling's in it.

Upvotes: 0

Views: 1098

Answers (1)

gccodec
gccodec

Reputation: 342

Yes you are right. The assembly plugin it seems to package to much.

You can do the follow:

  1. exclude scala library if on your execution environment are already installed. You can do this adding the following code to build.sbt
assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false)
  1. Setup the dependency that are already installed on your execution environment as Provided. For example
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.2.1" % Provided

Upvotes: 2

Related Questions