Hello,
I have setup a convention plugin for my my projects. Among other things, I want the plugin to apply the PMD plugin to my projects using a common rulesets file included in the convention plugin (not the actual project). I need help with how I can do that.
In my convention plugin project I have:
├── build.gradle
└── src
└── main
├── groovy
│ └── my-java-convention.gradle
└── resources
└── rulesets.xml
In my-java-convention.gradle, I have:
plugins {
id 'java'
id "io.freefair.lombok"
id "pmd"
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(8))
}
pmd {
consoleOutput = true
ruleSetFiles += files("rulesets.xml") // this where I want to reference the file included in the plugin
}
test {
useJUnitPlatform()
}
I am able to apply the convention plugin to my project and it is adding the pmd tasks to my project build. However, when pmd runs it complains because it’s looking for rulesets.xml in the my project directory (because filles("rulesets.xml) looks in the current project).
How can reference the rulesets.xml file included with the plugin not with the project. I know the file is available on the classpath because I can get to the file with getClass().getResource(“rulesets.xml”) which gives a URI object, but how to pass this as a file collection?
Please let me know if you know how to accomplish this. I plan to use the same approach for using spotless plugin where I want to include the java formatting rules file in the convention plugin.
Thanks in advance!