I am attempting to write a small plugin wrapper for PMD. I would like to package our custum rules.xml into the the jar. I have a simple build.gradle
apply plugin: 'groovy'
apply plugin: 'java'
dependencies {
compile gradleApi()
compile localGroovy()
compile files('pmd-core-5.2.3.jar')
compile files('pmd-java-5.2.3.jar')
}
sourceSets {
main {
resources {
srcDirs "src/main"
}
}
}
I also have my plugin class
package com.aonhewitt.gradle.plugins
import org.gradle.api.*
import org.gradle.api.file.*
import org.gradle.api.tasks.*
import org.gradle.api.tasks.TaskExecutionException
import org.gradle.api.plugins.quality.PmdPlugin
class UPointPMDPlugin implements Plugin {
/* This is the application of the Plugin * Project - the current project in which this plugin is running for. */ void apply(Project curProject) { curProject.plugins.apply(PmdPlugin)
curProject.pmd { rulePriority 2 // URL comes back with a valid value URL url = getClass().getResource("/pmd-ruleset.xml") // This fails to open the stream saying file not found String text = url.getText() //Added a test just to see if I could load a different file. This worked URL urlMan = getClass().getResource("/META-INF/MANIFEST.MF") String manText = urlMan.getText() } }
}
I have placed my pmd-ruleset.xml in src/main/resources
The compiled jar has the xml file in the root of the jar
When I apply the plugin it correctly loads the manifest file but fails to load the resource file. I am thinking that something in the groovy class loader is not recognizing resources as being on the class path. As I mentioned the URL comes back valid as it is not null and it returns a fully qualified path. For some reason when calling getResourceAsStream, it cannot locate the file.
Failed to apply plugin [class ‘com.aonhewitt.gradle.plugins.UPointPMDPlugin’]
JAR entry pmdrules/pmd-ruleset.xml not found in /media/gradle_1/upoint/upf-trunk/trunk/ah-gradle-plugins.jar
Any suggestions on how to get the resources to be recognized at runtime?