Skip to content
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

Spring Boot 3.2 Migration breaks Testcontainers due to exclusion of JUnit 4 as part of JUnit4to5Migration #477

Closed
tedyoung opened this issue Feb 7, 2024 · 3 comments · Fixed by #478
Assignees
Labels
bug Something isn't working

Comments

@tedyoung
Copy link

tedyoung commented Feb 7, 2024

What version of OpenRewrite are you using?

Ran command via

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-spring:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2

Which used Rewrite 5.22.0, relevant output:

[INFO] <<< rewrite:5.22.0:run (default-cli) < process-test-classes @ testcontainer-migrate <<<
[INFO] 
[INFO] --- rewrite:5.22.0:run (default-cli) @ testcontainer-migrate ---
[INFO] Using active recipe(s) [org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2]
[INFO] Using active styles(s) []
Downloading from central: https://repo.maven.apache.org/maven2/org/openrewrite/recipe/rewrite-spring/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/openrewrite/recipe/rewrite-spring/maven-metadata.xml (2.8 kB at 132 kB/s)
[INFO] Validating active recipes...
[INFO] Project [testcontainer-migrate] Resolving Poms...
[INFO] Project [testcontainer-migrate] Parsing source files
[INFO] Running recipe(s)...
[WARNING] Changes have been made to pom.xml by:
[WARNING]     org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2
[WARNING]         org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1
[WARNING]             org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0
[WARNING]                 org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7
[WARNING]                     org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_6
[WARNING]                         org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_5
[WARNING]                             org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_4
[WARNING]                                 org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration
[WARNING]                                     org.openrewrite.java.testing.junit5.JUnit4to5Migration
[WARNING]                                         org.openrewrite.maven.ExcludeDependency: {groupId=junit, artifactId=junit}
[WARNING]         org.openrewrite.maven.UpgradeParentVersion: {groupId=org.springframework.boot, artifactId=spring-boot-starter-parent, newVersion=3.2.x}
[WARNING] Please review and commit the results.

What is the smallest, simplest way to reproduce the problem?

This Spring Boot project's pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>dev.ted</groupId>
    <artifactId>testcontainer-migrate</artifactId>
    <version>0.0.1</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

What did you expect to see?

I expected only the Spring Boot parent version to change, with no other changes:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>dev.ted</groupId>
    <artifactId>testcontainer-migrate</artifactId>
    <version>0.0.1</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-testcontainers</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>

What did you see instead?

As in issue #429, the JUnit 4 exclusion was added to the Testcontainers dependency block, which breaks the functionality of Testcontainers:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>dev.ted</groupId>
    <artifactId>testcontainer-migrate</artifactId>
    <version>0.0.1</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-testcontainers</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>junit-jupiter</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

</project>
@timtebeek
Copy link
Contributor

Hi @tedyoung ; Thanks for chiming in with those details! For now I've applied the same fix as we saw earlier in #430

There's a bit of a balance here where that exclusion often helps to fully wean folks off JUnit 4; but of course for Testcontainers we can't yet fully do that. Luckily the folks at AtomicJar/Docker are also involved here (see our Testcontainers recipes), so who knows we might be able to migrate their users off of JUnit 4 with recipes in the future.

@tedyoung
Copy link
Author

tedyoung commented Feb 7, 2024

Thanks for the quick response!

I hope that the Testcontainer folks fix testcontainers/testcontainers-java#970 before it hits its 6th birthday. 😦

@timtebeek
Copy link
Contributor

You're welcome; glad this was an easy fix. We just did a release yesterday, but until the next one in a week or two you can use
our snapshot versions. And let me know if you encounter anything else, or we can help in some other way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants