Applying the Checkstyle plugin twice for the same project

Hello,
I’d like to use Checkstyle to validate my sources’ copyright comment.
For this purpose, I’ll have to change the checkstyle task to apply to all sources instead of just the project’s java sources.

However, instead of changing my current checkstyle task to apply to all sources, I’d like to be able to create a new checkstyle task which would read a different checkstyle configuration and which I’d be able to run without running the usual checkstyle task. I.e., I’d like to be able to apply the checkstyle plugin twice with different configuration in the same project.

Is this currently possible via the Gradle build DSL? Or would I have to copy the checkstyle plugin to a new plugin and such?

Any advice would be much appreciated.
Thanks!

You can never apply a plugin multiple times.
Whenever you apply a plugin a second, third, … time it is just a noop.
But you don’t need to apply the plugin multiple times and you don’t need to create a separate plugin.
Just create additional tasks of type Checkstyle with whatever configuration you need.
Of course if you need that reusable, you could create a convention plugin that does that for you.

Thanks @Vampire, that makes perfect sense.

1 Like