gradle-lint-plugin icon indicating copy to clipboard operation
gradle-lint-plugin copied to clipboard

Is there any way to create a custom rules for 'gradle-lint-plugin' and add them to the classpath?

Open dgroup opened this issue 3 years ago • 4 comments

Hi, In this article https://github.com/nebula-plugins/gradle-lint-plugin/wiki/Writing-A-Rule there is an instruction on how to create a rule. In case if I want to implement several rules for my own team, how can I use them within gradle-lint-plugin?

For example, Gradle PMD plugin supports dependency section (with dependency scope=pmd) that allows connecting other rules implemented outside the PMD team https://docs.gradle.org/current/userguide/pmd_plugin.html#sec:pmd_dependency_management

apply plugin: 'pmd'

dependencies {
   ...
   pmd "io.github.dgroup:arch4u-pmd:${version}"    // use latest arch4u-pmd rules version
   ...
}

pmd {
   consoleOutput = true
   ruleSetFiles = files("io/github/dgroup/arch4u/pmd/arch4u-ruleset.xml")
   ...
}

dgroup avatar Mar 07 '22 09:03 dgroup

Did you land somewhere with this, @dgroup? I asked a similar question in #395 before seeing yours.

exaucae avatar Aug 29 '23 16:08 exaucae

@exaucae, I made a fork with several rules and applied them to my projects directly.

dgroup avatar Aug 29 '23 19:08 dgroup

Thank you!

exaucae avatar Aug 30 '23 09:08 exaucae

this line could be the one to change if we want to feed custom rules to the plugin: https://github.com/nebula-plugins/gradle-lint-plugin/blob/280804cbbdcce703284921b34fe8719a0a84f661/src/main/groovy/com/netflix/nebula/lint/plugin/GradleLintPlugin.groovy#L33

The classloader is used by the LintRuleRegistry to get rulesets: https://github.com/nebula-plugins/gradle-lint-plugin/blob/main/src/main/groovy/com/netflix/nebula/lint/plugin/LintRuleRegistry.groovy#L27-L31

exaucae avatar Sep 13 '23 21:09 exaucae