Skip to content

JUnit4to5Migration excludes required dependency of testcontainers #429

@simonzn

Description

@simonzn

org.testcontainers:testcontainers has a hard dependency on Junit4, see testcontainers/testcontainers-java#970

The JUnit4to5Migration adds an exclusion to the dependency, which breaks our builds. The issue above suggests crude workarounds like creating dummy classes in your project, but it seems cleaner to not add the exclusion in the first place.

As a workaround I added another recipe to our list which reverts the change; this has the (IMO cosmetic) issue that it creates an empty diff. Pull request is coming up for discussion.

I am aware this is really an issue with testcontainers and not so much with the JUnit4to5Migration recipe, but I think many projects could benefit from a workaround. This should be safe as well - once the issue in testcontainers is resolved it's a NOOP.

What version of OpenRewrite are you using?

I am using

  • OpenRewrite 8.9.0
  • rewrite-maven-plugin 5.14.0-SNAPSHOT
  • rewrite-testing-frameworks 2.1.0

How are you running OpenRewrite?

I am executing the JUnit4to5Migration recipe with the Maven command line.

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

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.jackson</groupId>
    <artifactId>test-plugins</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <version>1.18.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

What did you expect to see?

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.jackson</groupId>
    <artifactId>test-plugins</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <version>1.18.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

What did you see instead?

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.jackson</groupId>
    <artifactId>test-plugins</artifactId>
    <version>1.0.0</version>
    <dependencies>
        <dependency>
            <groupId>org.testcontainers</groupId>
            <artifactId>testcontainers</artifactId>
            <version>1.18.3</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</project>

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions