openrewrite / openrewrite/rewrite-testing-frameworks

Exclude Junit 4 indefinitely using maven-enforcer-plugin

Open
#196 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

recipe
Dominant language
Java
Stars
100
Forks
105
Avg merge
2h 25m
Merged PRs (30d)
9

Description

Running JUnit4to5Migration does not guarantee that in the future team members will not include Junit4 to the classpath accidently (IDEs are the main one to do so)

In my team, we are adding the following configuration to our build after migrating to Junit 5 to avoid adding it in the future.

This is something that we could consider as part of the migration recipe as well


<build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <executions>
                    <execution>
                        <id>ban-junit-4</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <rules>
                                <bannedDependencies>
                                    <excludes>
                                        <exclude>junit:junit</exclude>
                                    </excludes>
                                    <message>JUnit 4 is banned from this project in favor of JUnit 5
                                    </message>
                                </bannedDependencies>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the JUnit4to5Migration entry point and inspect how the migration currently updates Maven build configuration. Add the requested JUnit 4 exclusion through maven-enforcer-plugin, then verify the migration output and its existing tests cover the resulting configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.