Skip to content

Add recipe to upgrade Gatling 3.x to 3.16 - #1259

Merged
timtebeek merged 24 commits into
openrewrite:mainfrom
sullis:gatling-3.16-migration
Nov 17, 2026
Merged

timtebeek merged 24 commits into
openrewrite:mainfrom
sullis:gatling-3.16-migration

Conversation

@sullis

@sullis sullis commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

What's changed

Adds org.openrewrite.java.testing.gatling.UpgradeToGatling3_16. It upgrades Gatling simulations written in Scala, Java or Kotlin from 3.0 onward to 3.16, following the official upgrade guides.

  • Build files: io.gatling.highcharts:gatling-charts-highcharts and io.gatling:gatling-* → 3.16.x, gatling-maven-plugin → 4.x, io.gatling.gradle → 3.16.x.
  • ReplaceGatlingDollarExpressionLanguage (Java, Kotlin, Scala): rewrites ${…} → #{…}. Gatling deprecated ${} in 3.7 and stopped interpreting it in 3.11. Kotlin's escaped "\${id}" becomes "#{id}". Scala interpolated strings and Kotlin string templates are left alone. Only sources importing io.gatling are touched, so other ${…} placeholders (Spring, Maven filtering) are safe.
  • MigrateGatlingScalaDsl (Scala):
    • heavisideUsers → stressPeakUsers
    • WhiteList/BlackList → AllowList/DenyList
    • polling → poll
    • ignoreDefaultChecks/ignoreDefaultHeaders → ignoreProtocolChecks/ignoreProtocolHeaders
    • stopInjector(If) → stopLoadGenerator(If)
    • maxConnectionsPerHostLikeXXX → maxConnectionsPerHost(n), with counts taken from the Gatling bytecode
    • feeder convert → transform
    • check transform/transformOption taking the Session → …WithSession (3.4)
  • ReplaceScalaPostfixDurations (Scala): 5 seconds → 5.seconds for the scala.concurrent.duration units, as recommended by the 3.5 upgrade guide. Postfix notation needs -language:postfixOps and is dropped in Scala 3. Only argument-less infix calls with a duration unit name are rewritten, so a max b or x plus y are left alone.
  • MigrateGatlingExitBlockOnFail (Java SDK, so Java and Kotlin): exitBlockOnFail(chain) → exitBlockOnFail().on(chain) (3.10). Handles both the static and the instance form.
  • MigrateGatlingChoice (Java SDK): Choice.withKey/withWeight → onCase(..).then(..)/percent(..).then(..) (3.11).
  • ChangeMethodName for the Java SDK's stopInjector/stopInjectorIf (3.12).

Notes for reviewers

  • Scala matching is by name. With a real classpath, rewrite-scala does attribute types, but they are misplaced: for example, apply wrappers carry the enclosing call's type. Type-based matching would be fragile. MigrateGatlingScalaDsl and ReplaceScalaPostfixDurations therefore only apply in .scala sources importing io.gatling, and the DSL renames skip names the source declares itself. The shared precondition lives in GatlingSources. The main code does not depend on rewrite-scala; it is added as a test dependency only.
  • Java SDK matching is by type. MigrateGatlingExitBlockOnFail, MigrateGatlingChoice and the stopInjector renames use method matchers against io.gatling.javaapi.core, so they also cover Kotlin sources.
  • The upgrade guides overstate the Java scope. The 3.11 guide lists polling, WhiteList/BlackList, maxConnectionsPerHostLikeXXX and ignoreDefaultChecks as Java/Scala. The jars show the Java SDK (since 3.7) never had them, so those renames are Scala-only.
  • Type tables:
    • Main gains gatling-core/gatling-core-java 3.16.0 for the templates. The Java SDK's builders are bounded by the Scala ones, so both are needed.
    • Test gains gatling-core-java and gatling-http-java 3.9.5, plus the Scala gatling-core and gatling-http jars they are bounded by. 3.9.5 is the last version with exitBlockOnFail(ChainBuilder).
    • Apart from these entries, the type tables are unchanged.
  • Left alone (listed in the recipe description): Java 11 baseline (3.10), adding scala-maven-plugin for Maven Scala projects (plugin 4.x no longer compiles Scala), and javax.jms → jakarta.jms (3.14, vendor dependent).
  • Also left alone: the third-party com.github.lkishalmi.gatling Gradle plugin. Only the official io.gatling.gradle plugin is upgraded.

Testing

  • 27 new tests across Scala, Java, Kotlin, Maven and Gradle, all passing.
  • They were run locally against released rewrite versions, because snapshot dependencies were not resolvable here. Relying on CI for the snapshot build.
  • In that local setup, 28 unrelated tests fail (JMockit, PowerMock, Mockito, Cucumber, Gradle Kotlin DSL); the same 28 fail on an unmodified main.

Related work

https://github.com/sullis/sullis/blob/main/hacktoberfest-2026-10-31.md

🤖 Generated with Claude Code

Upgrade Gatling simulations written in Scala, Java or Kotlin from 3.0 onward
to 3.16: bump the Gatling dependencies and the Maven and Gradle plugins,
replace the `${}` Expression Language with `#{}`, and migrate the DSL methods
removed along the way.

Scala sources are not reliably type attributed against the Gatling Scala DSL,
so Scala methods are matched by name in sources importing Gatling, skipping
names the source declares itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sullis
sullis force-pushed the gatling-3.16-migration branch from 398a531 to 540cd77 Compare November 10, 2026 00:47
@sullis
sullis marked this pull request as ready for review November 10, 2026 00:52
The DSL is matched by name, so `Map("a" -> 1).transform((k, v) => v + 1)` in a
simulation was renamed to `transformWithSession`, which does not compile. The
Scala standard library is type attributed even where Gatling is not, so skip
calls whose method type is declared in `scala.collection`.

@timtebeek timtebeek left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @sullis! Nice to see Scala, Java and Kotlin all covered, and the notes on where the upgrade guides overstate the Java scope helped a lot. I've pushed a few commits myself, so there's nothing left for you to change. For any next PRs:

  1. Merged main, which also triggered a fresh CGP run. The earlier failure wasn't caused by this PR: CGP's Maven cache answered 503 for the recipe-library plugin.

  2. Applied OpenRewriteRecipeBestPractices (f0299ac): reduce(..) instead of visit(..) with a captured set in declaredNames, explicit imports, and one classpathFromResources entry per line.

  3. MigrateGatlingScalaDsl renamed Map("a" -> 1).transform((k, v) => v + 1) in a simulation to transformWithSession, which doesn't compile (5756bce). This is now covered by the type guard in item 8.

  4. Trimmed the UpgradeToGatling3_16 description to its overall effect plus what it leaves alone (dc99d5f). The included recipes already describe themselves, and a composite description tends to go stale as entries get added.

  5. ReplaceGatlingDollarExpressionLanguage also rewrote ${} placeholders meant for something else, as in System.getProperty("baseUrl", "${BASE_URL}") (748a4d8). It now skips a string when every call it passes through, up to the enclosing statement, is typed and declared outside io.gatling. Strings that reach Gatling through other calls, such as headers(Map.of("X-Token", "${token}")), are still rewritten, as are constants and untyped Scala DSL calls.

  6. ElFileBody templates use the same Expression Language, so their ${} also stops working in 3.11. The composite description now says those files are left alone (a206578); rewriting them could be a follow-up.

  7. The Scala recipes now also cover .sc scripts, as used to run simulations with scala-cli (3948b26). ScalaParser parses those too, but the precondition only matched .scala.

  8. With openrewrite/rewrite#9914, the Scala parser can read the Gatling type tables. The Scala tests now parse against Gatling 3.9, like the Java and Kotlin ones (451f6d3). The DSL renames still match by name, because the declaring types moved between Gatling versions: WhiteList is a CoreDsl method in 3.9 but a case class in 3.0. They now skip anything typed outside io.gatling, such as the source's own declarations or the Scala library. That one guard replaces both the scan for names the source declares and the scala.collection skip.

  9. openrewrite/rewrite#9915 now parses a typed call without parentheses, such as 5.seconds, as a method invocation. ReplaceScalaPostfixDurations produces that same shape, and matches typed units through DurationConversions (21e2c17). Renamed calls also get renamed method types now, and the test calls ignoreDefaultChecks on a request, where Gatling defines it. Code that stays untyped still gets matched by name, because the parser keeps modelling it the old way.

  10. The recipes found Gatling sources by matching import package names, because Scala imports used to be untyped. Since openrewrite/rewrite#9983 they are typed, so UsesType<>("io.gatling..*", false) works for Scala, Java and Kotlin, and GatlingSources is gone (84e1716). The Scala-only recipes need no file filter either (ad22129): they can't change Java or Kotlin code, which keepJavaSdkTransform checks. One difference: unlike the old import check, UsesType skips a Java or Kotlin source whose only Gatling imports are unresolved wildcards, so such a source is now left alone.

  11. A fully qualified io.gatling.javaapi.core.CoreDsl.exitBlockOnFail(chain) became CoreDsl.exitBlockOnFail().on(chain), without an import of CoreDsl, so it didn't compile (e5e67cb). The recipe now keeps the call's own qualifier, and fullyQualifiedStaticMethod covers it.

  12. Removed the recipeList comments in gatling.yml (cc3882e). They repeated what each recipe's own description says, and comments there are best kept for where ordering matters.

openrewrite/rewrite#9914 and #9915 have both landed, and the 33 Gatling tests pass against today's rewrite snapshot.

A simulation may hold `${}` placeholders meant for something other than Gatling,
as in `System.getProperty("baseUrl", "${BASE_URL}")`. Skip a string when every
call it is passed through up to the enclosing statement is typed and declared
outside `io.gatling`. Strings reaching Gatling through other calls, such as
`headers(Map.of("X-Token", "${token}"))`, and constants are still rewritten, as
are untyped calls, which Gatling's Scala DSL calls are.
`ScalaParser` also parses `.sc` scripts, as used to run Gatling simulations with
scala-cli, but `GatlingSources.isScala` only matched `.scala` files.
@timtebeek

Copy link
Copy Markdown
Member

I'd noticed that we had to work around some missing type information here that I think is best addressed upstream first:

We'll see what we can do to improve the situation there, and then come back here to strip out the string based matching.

Thanks for bringing this to our attention!

# Conflicts:
#	build.gradle.kts
#	src/main/resources/META-INF/rewrite/classpath.tsv.gz
With openrewrite/rewrite#9914, type table stubs of Scala libraries resolve in
the Scala parser, so the Scala tests now parse against the Gatling 3.9 type
tables, like the Java and Kotlin tests already did. Typed, the source's own
declarations and the Scala library are recognised by their types, so the
`declaredNames` scan and the `scala.collection` special case give way to one
guard: rename only what is untyped or attributed to `io.gatling`.

Methods are still matched by name: their declaring types moved between Gatling
versions, so `WhiteList` is a `CoreDsl` method in 3.9 but a case class in 3.0,
and calls without parentheses carry no method type yet (openrewrite/rewrite#9913).

The three no-change Scala tests fail until openrewrite/rewrite#9914 is in a
snapshot, as without it the Gatling import leaves the whole source untyped.
@timtebeek

Copy link
Copy Markdown
Member

One final PR to land before we can retry here:

… types in sync

openrewrite/rewrite#9915 parses a typed call without parentheses, such as
`5.seconds`, as a `J.MethodInvocation` whose arguments carry `OmitParentheses`.
`ReplaceScalaPostfixDurations` now produces that instead of a `J.FieldAccess`,
and matches typed units by `DurationConversions`, falling back to their names
where the enclosing Gatling call leaves them untyped. The field access branch
of `MigrateGatlingScalaDsl` stays for untyped sources, which are still parsed
that way.

As Scala calls into Gatling are now typed, the renamed calls get renamed method
types, and `maxConnectionsPerHost` takes the `int` it is passed.

`ignoreDefaultChecks` and `ignoreDefaultHeaders` are request builder methods,
so the test now calls them on a request rather than on the protocol.
The precondition matched imports by package name because Scala imports used to
be untyped. Since openrewrite/rewrite#9983 they are typed like Java, and
`UsesType` also counts unresolved single-type imports, so it covers Scala,
Java and Kotlin alike. The Scala recipes narrow it to `.scala` and `.sc` files
with `FindSourceFiles`.

Unlike the import check, `UsesType` skips a Java or Kotlin source whose only
Gatling imports are unresolved wildcards, so such a source is now left alone.
`UsesType` alone suffices. Outside Scala, postfix durations never carry the
`InfixNotation` marker, and the only DSL names the Java SDK shares are
`stopInjector`, which gets the same rename there, and the single-parameter
`transform`, which `transformWithSession` never matches.
A fully qualified `io.gatling.javaapi.core.CoreDsl.exitBlockOnFail(chain)` became
`CoreDsl.exitBlockOnFail().on(chain)` without an import of `CoreDsl`, which does
not compile. Reuse the call's own qualifier instead.
timtebeek and others added 5 commits November 17, 2026 13:35
A qualified static call's select is typed with its class, just like an
instance receiver, so both go through the same `#{any(..)}` parameter instead of
printing the qualifier into the template code.
…l/logHttp options

Found by running the recipe on real Gatling projects and compiling against 3.16.1:
- FeederBuilder.Batchable was removed after 3.11, so it becomes FileBased
- the io.gatling.gradle plugin dropped logLevel and logHttp in 3.11, which breaks build evaluation
- document the plugin ordering and Engine/Recorder launcher changes that are left alone

@timtebeek timtebeek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot again! Took a little while longer after spotting the upstream improvements to be made for Scala, but that's now in a better shape as well. I've also applied these at scale against OSS repositories, which led to the last recipe added.

Hope these recipes help you there!

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Nov 17, 2026
@timtebeek
timtebeek merged commit 985cd70 into openrewrite:main Nov 17, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants