openrewrite / rewrite-testing-frameworks

OpenRewrite recipes that perform common Java testing migration tasks.
Apache License 2.0
77 stars 73 forks source link

Exclude Junit 4 indefinitely using maven-enforcer-plugin #196

Open yeikel opened 2 years ago

yeikel commented 2 years ago

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>
yeikel commented 2 years ago

If a new recipe makes more sense, we could consider that as well

pway99 commented 2 years ago

I think a standalone recipe is a good option, the AddPlugin should make it a fairly simple addition to the junit recipes