【发布时间】:2021-01-21 16:48:40
【问题描述】:
问题
我创建了一个 Scala 和 Gatling 项目,我想用它来执行一些负载测试。我的想法是构建一个可执行的 jar,然后我只需执行它即可运行所述负载测试。
到目前为止,我在 IDE 中运行负载测试没有任何问题。但是,当我尝试用以下方式组装它时:
gradle assemble
jar 是空的,即包含来自src/main/scala 的实用程序类,但没有来自src/gatling/* 的任何内容(请参阅下面的设置)。
我尝试过使用胖罐子,但该任务给了我错误:
Execution failed for task ':fatJar'.
> Cannot expand ZIP 'D:\projects\load-test\build\classes\java\main' as it does not exist.
我不知道为什么它首先需要 java。
我的设置
我的项目结构如下:
load-test/
├── src/
│ ├── gatling/
│ │ ├── resources
│ │ └── scala
│ ├── main/
│ │ ├── resources
│ │ └── scala
│ └── test/
│ ├── resources
│ └── scala
├── ...
└── build.gradle
我发现 Gatling 插件非常顽固,它只包含 gatlingCompileClasspath 中的 Gatling 依赖项。所以为了能够编写负载测试,我需要有一个gatling 源集。 main/scala 目录用于实现一些实用功能,例如创建自定义时间戳等。test/scala 测试这些。
我的build.gradle如下:
plugins {
id "com.github.maiflai.scalatest" version "0.25"
id 'io.gatling.gradle' version "3.4.0"
id "scala"
}
apply plugin: "scala"
apply plugin: "com.github.maiflai.scalatest"
compileScala.targetCompatibility = 1.8
ScalaCompileOptions.metaClass.useAnt = false
repositories {
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
}
sourceSets {
gatling {
scala.srcDirs = ["src/gatling/scala"]
resources.srcDirs = ["src/gatling/resources"]
}
test {
scala.srcDirs = ["src/test/scala"]
resources.srcDirs = ["src/test/resources"]
}
}
dependencies {
testCompile "gradle.plugin.com.github.maiflai:gradle-scalatest:0.25"
testCompile "org.scala-lang:scala-library:2.12.12"
testCompile 'org.scalatest:scalatest_2.12:3.0.0'
testRuntime 'org.pegdown:pegdown:1.4.2'
}
gatling {
toolVersion = '3.4.0'
scalaVersion = '2.12.12'
simulations = {
include "**/*Simulation.scala"
}
systemProperties = ['file.encoding': 'UTF-8']
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Version': project.version,
'Main-Class': 'io.gatling.app.Gatling'
}
setArchiveBaseName project.name + '-all'
from {
configurations.gatlingRuntimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude 'META-INF/MANIFEST.MF'
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
}
with jar
}
【问题讨论】:
-
很遗憾没有。这对我没有帮助:(
-
你可能是对的。这很令人沮丧,但似乎只能使用 gradle task 运行模拟。