I'm building a Groovy plugin for Android Studio which will execute some gradle tasks. However I need to load a XML file from within the JAR file from where the code executes.
The JAR file is as following:
- com/packagename/code
- META-INF/gradle-plugins
- filename.xml
Because the xml file is at the root of the JAR I used this to load in the resource into an inputstream
new InputStreamReader(CheckStyleTask.class.getResourceAsStream("/filename.xml"))
The weird thing is that it only works sometimes. Sometimes it returns the file, sometimes it returns null. For example I took this line to check the path:
println(CheckStyleTask.class.getResource("/filename.xml").getPath())
And the path is completely right. So it is able to find the file with getResource, but with getResourceAsStream it returns null.
I think something is wrong with the building of the jar but in IntelliJ I set the gradle task as 'jar' which did create a working jar with working xml file.
Am I doing anything wrong regarding the building or is there anything wrong with the xml file?