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

Let build fail if multiple "bannedImport" elements are used, instead of "bannedImports" with multiple "bannedImport"-elements inside #112

Open henrykuijpers opened 11 months ago

henrykuijpers commented 11 months ago

We had a few configurations in our project, that had multiple bannedImport-elements. The first (or the last) is only considered, the others are ignored.

We should add something to prevent this from happening.

skuzzle commented 11 months ago

I will look into this but I'm not sure whether this is doable. It depends on whether maven actually calls the setter twice when binding the XML values to the model. If it does, then adding a check should be fairly simple. If it doesn't, then adding a check for this might be impossible.

Actually, if the setter would be called twice we could consider getting rid of the bannedImports element altogether

skuzzle commented 11 months ago

@henrykuijpers Could you please post your configuration? I just tried the following:

<configuration>
    <rules>
        <RestrictImports>
            <bannedImport>java.util.*</bannedImport>
            <bannedImport>java.*</bannedImport>
        </RestrictImports>
    </rules>
</configuration>

And it fails with the following message:

Caused by: java.lang.IllegalArgumentException: If you want to specify multiple banned imports you have to wrap them in a <bannedImports> tag