skuzzle / restrict-imports-enforcer-rule

Gradle plugin & Maven Enforcer rule that restricts usage of unwanted imports in Java, Kotlin and Groovy source files.
MIT License
75 stars 12 forks source link

Replace deprecated EnforcerRule and EnforcerRule2 implementations #90

Open skuzzle opened 1 year ago

skuzzle commented 1 year ago

The interfaces EnforcerRule and EnforcerRule2 have been deprecated in favor of the new abstract class AbstractEnforcerRule. However this poses a big problem as our rule implementation already need to inherit from BannedImportGroupDefinition in order to provide convenient XML configuration.

We probably need to give up on the convenience configuration in order to get rid of the deprecations.

Currently it is possible to either configure a single banned group or multiple groups. When configuring a single group, this group does not need to be nested in <groups></groups>. This is achieved by inheriting from BannedImportGroupDefinition.

Changing this would break existing rule usages and introduce inconveniences when configuring the rule for simple use cases

See also: https://maven.apache.org/enforcer/enforcer-api/writing-a-custom-rule.html

skuzzle commented 1 year ago

I reckon we could still make this work by not inheriting from BannedImportGroupDefinition and instead copy its contents to the rule implementation. ~That's ugly to maintain though~ Just tried it out and it was pretty straight forward. Instead of delegating to the super class, we can just delegate to an actual instance of BannedImportGroupDefinition.