[英]Get ClassLoader from gradle org.gradle.api.Project?
I'm writing a gradle plugin that wishes to read specific properties file from resources of a project of which this plugin is applied to. 我正在编写一个gradle插件 ,希望从应用此插件的项目的资源中读取特定的属性文件。 To read those resources, I need a classpath of the project.
要读取这些资源,我需要一个项目的类路径。 Currently I'm going with:
目前我要去:
org.gradle.api.Project.getBuildscript().getClassLoader().getResourcesAsStream(...)
But it always returns null even though such resource exists in that project. 但即使该项目中存在此类资源,它也始终返回null。
Gradle buildscript is comilped and put into a local cache, so the project is not on the classpath of buildscript classloader. Gradle buildscript被编译并放入本地缓存中,因此项目不在buildscript类加载器的类路径中。 What you need is probably
org.gradle.api.Project. absoluteProjectPath()
你需要的可能是
org.gradle.api.Project. absoluteProjectPath()
org.gradle.api.Project. absoluteProjectPath()
. org.gradle.api.Project. absoluteProjectPath()
。
eg To read "src/main/resources/META-INF/MANIFEST.MF": 例如,阅读“src / main / resources / META-INF / MANIFEST.MF”:
try(Reader in = new FileReader(project.absoluteProjectPath( "src/main/resources/META-INF/MANIFEST.MF" ))) {
//...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.