Is there a best practice to remove old dependencies from maven pom?

Viewed 182

My company is trying to get our team off Junit3 (and 4) and onto Junit5.

Our pom file has dependencies for Junit3, 4 and 5 already.

I'd like to somehow mark Junit3 and 4 as "deprecated at my company" to give anyone who is trying to use these older versions a visual clue in the UI that we want to stop using these.

Is there a method to mark some dependency in Maven as "deprected at my company?"

Short of that, I suppose we could write a checkstyle rule or some other static analysis, but I really think it would be less obtrusive to have the visual indicator (like javadocs or @Deprecated annotations).

Thoughts or addins that would do this?

If IDE matters, we have IntelliJ, Visual Studio code and a handful of stalwarts still on vim.

2 Answers

I'd like to find a utility that doesn't fail if any instance of a banned dependency is found, only new instances.

It looks like ArchUnit may give you the flexibility you are asking for. For example, a simple test below fails if any of the classes in the analyzed packages actually use classes from the org.junit package:

package com.stackoverflow.example;

import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition;

@AnalyzeClasses(
    packages = "<root package of your module>"
)
public class JUnit4UsageTest {

    @ArchTest
    public static final ArchRule RULE_NO_CLASSES_SHOULD_ACCESS_JUNIT4_PACKAGES =
        ArchRuleDefinition.noClasses()
       .should()
       .dependOnClassesThat()
       .resideInAPackage("org.junit");

}

The DSL provided by the ArchUnit is powerful enough to express the rules, as long as the information is preserved in the class file.

The library also provides support for the freezing arch rules - they succeed for known recorded issues, but fail for any new one.

Related