Get ClassLoader from gradle org.gradle.api.Project?

I am writing a gradle plugin that wants to read a specific properties file from the project resources to which this plugin is applied. To read these resources, I need a project classpath. Currently I am going to:

org.gradle.api.Project.getBuildscript().getClassLoader().getResourcesAsStream(...) 

But it always returns null, even if such a resource exists in this project.

+5
source share
1 answer

Gradle buildscript is added and placed in the local cache, so the project is not in the path of the buildscript class loader classes. You probably need org.gradle.api.Project. absoluteProjectPath() org.gradle.api.Project. absoluteProjectPath() .

eg. To read "src / main / resources / META-INF / MANIFEST.MF":

 try(Reader in = new FileReader(project.absoluteProjectPath( "src/main/resources/META-INF/MANIFEST.MF" ))) { //... } 
0
source

Source: https://habr.com/ru/post/1271800/


All Articles