Skip to content

Remove withLocalCompose(true) in the Testcontainers 2 migration - #1281

Merged
timtebeek merged 2 commits into
mainfrom
testcontainers2-remove-local-compose
Nov 3, 2026
Merged

timtebeek merged 2 commits into
mainfrom
testcontainers2-remove-local-compose

Conversation

@timtebeek

Copy link
Copy Markdown
Member

Testcontainers2Migration changes DockerComposeContainer to ComposeContainer but keeps .withLocalCompose(true). Testcontainers 2 removed withLocalCompose(boolean) from both classes, so the call no longer compiles. In Testcontainers 2 a ComposeContainer built from compose files alone, without a DockerImageName, already uses the local Docker Compose binary, so withLocalCompose(true) has no replacement and can go.

Before:

DockerComposeContainer env = new DockerComposeContainer(new File("docker-compose.yml"))
        .withLocalCompose(true)
        .withTailChildContainers(true);

After the migration today (does not compile):

ComposeContainer env = new ComposeContainer(new File("docker-compose.yml"))
        .withLocalCompose(true)
        .withTailChildContainers(true);

After this change:

ComposeContainer env = new ComposeContainer(new File("docker-compose.yml"))
        .withTailChildContainers(true);

This surfaced while validating the Spring Boot 4.1 migration over open source Spring Boot 3.x repositories, in adorsys/open-banking-gateway (opba-protocols/sandboxes/xs2a-sandbox/.../BasicTest.java): cannot find symbol: method withLocalCompose(boolean) on ComposeContainer.

This adds RemoveLocalCompose, which removes withLocalCompose(true) on DockerComposeContainer and ComposeContainer, in a chain or as a statement, using RemoveMethodInvocationsVisitor with isTrueArgument(). It runs in Testcontainers2Migration before the type change. withLocalCompose(false) and non-literal arguments are left alone: their Testcontainers 2 form is a constructor that takes a DockerImageName, which needs a choice of image.

Is this the right change?

  • Do we already have it? No.
  • Could it be declarative? Not quite: RemoveMethodInvocations removes the call whatever its argument, which would turn withLocalCompose(false) into local compose without a word. The recipe is a thin wrapper around RemoveMethodInvocationsVisitor with an argument predicate.
  • Is it worth it? Yes, withLocalCompose(true) is the usual way to use Docker Compose v2 from Testcontainers 1.x, and every such call breaks.
  • Does it fix the problem, or move it? It fixes it for true, which is the Testcontainers 2 default for these constructors.
  • Does it do no harm? Only the literal true is removed; false and expressions stay, for a person to decide.

Tests: new RemoveLocalComposeTest (removal in a chain and as a statement; false and a variable unchanged) and TestcontainersBestPracticesTest#composeContainerWithLocalCompose (the full migration on the shape from open-banking-gateway; failed before). TestcontainersBestPracticesTest and Testcontainers2LocalStackTest pass.

@timtebeek
timtebeek merged commit 8e1b932 into main Nov 3, 2026
1 check passed
@timtebeek
timtebeek deleted the testcontainers2-remove-local-compose branch November 3, 2026 12:45
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Nov 3, 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.

1 participant