Skip to content

chore: Use ExecOperations #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/groovy/io/gatling/gradle/GatlingRunTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskExecutionException
import org.gradle.api.tasks.VerificationException
import org.gradle.api.tasks.options.Option
import org.gradle.process.ExecOperations
import org.gradle.process.ExecResult
import org.gradle.process.JavaExecSpec
import org.gradle.util.GradleVersion

import javax.inject.Inject
import java.nio.charset.StandardCharsets

class GatlingRunTask extends DefaultTask {
Expand Down Expand Up @@ -64,7 +66,11 @@ class GatlingRunTask extends DefaultTask {
@OutputDirectory
File gatlingReportDir = project.file("${project.reportsDir}/gatling")

GatlingRunTask() {
private ExecOperations execOperations

@Inject
GatlingRunTask(ExecOperations execOperations) {
this.execOperations = execOperations
outputs.upToDateWhen { false }
}

Expand All @@ -81,6 +87,8 @@ class GatlingRunTask extends DefaultTask {
}
} else {
def gatlingExt = project.extensions.getByType(GatlingPluginExtension)
final def thisExecOperations = execOperations
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't do this, I get:

    Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'execOperations' for task ':gatlingRun' of type io.gatling.gradle.GatlingRunTask.
        at org.gradle.internal.metaobject.AbstractDynamicObject.getMissingProperty(AbstractDynamicObject.java:85)
        at org.gradle.internal.metaobject.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:62)
        at io.gatling.gradle.GatlingRunTask_Decorated.getProperty(Unknown Source)
        at io.gatling.gradle.GatlingRunTask$_gatlingRun_closure3.doCall$original(GatlingRunTask.groovy:100)
        at io.gatling.gradle.GatlingRunTask$_gatlingRun_closure3.doCall(GatlingRunTask.groovy)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try with this.execOperations (instead of execOperations alone?)
I know that groovy try to find on it or on delegate when available

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I did, and it fails the same way. I agree it's a groovy issue and not a gradle one.


Map<String, ExecResult> results = simulationClasses().collectEntries { String simulationClass ->
getLogger().info("Running simulation " + simulationClass + ".")
Properties propagatedSystemProperties = new Properties()
Expand All @@ -90,7 +98,7 @@ class GatlingRunTask extends DefaultTask {
}
}

[(simulationClass): project.javaexec({ JavaExecSpec exec ->
[(simulationClass): thisExecOperations.javaexec({ JavaExecSpec exec ->
exec.mainClass.set(GatlingPluginExtension.GATLING_MAIN_CLASS)
exec.classpath = project.configurations.gatlingRuntimeClasspath
exec.jvmArgs this.jvmArgs ?: gatlingExt.jvmArgs
Expand Down