restrict-imports-enforcer-rule icon indicating copy to clipboard operation
restrict-imports-enforcer-rule copied to clipboard

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

Open henrykuijpers opened this issue 2 years ago • 2 comments
trafficstars

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.

henrykuijpers avatar Nov 14 '23 09:11 henrykuijpers

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 avatar Nov 24 '23 11:11 skuzzle

@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

skuzzle avatar Nov 27 '23 09:11 skuzzle