我有一个包含两个子项目的gradle主项目,一个是java,另一个是groovy库。
java项目是一个使用groovy库的http服务器。
所有这些都可以编译,并且运行得很好,但我尝试的是动态编译groovy库(在每个http请求上),这样我就不必在每次更改groovy库时重新编译所有东西。
这个是可能的吗?
发布于 2019-07-02 03:43:11
它正在使用GroovyClassLoader。在处理静态类字段和交叉引用时,我遇到了一些警告,但我基本上在我的几个项目中使用了这个设置。在某些情况下,您可能需要注意加载顺序。
def groovyClassLoader = new GroovyClassLoader()
def classPaths = [ '/opt/myProject/src/groovy/' ]
// First, add Class Paths -- these are the root directories of your code files.
for (String path in classPaths) {
File dir = new File(path)
groovyClassLoader.addClasspath(dir.getAbsolutePath())
}
def src = [ '/opt/myProject/src/groovy/net/me/program/' ]
// Now, load groovy files
for (String path in src) {
// Iterate differently if no access to FileUtils
File[] directoryListing = FileUtils.listFiles(new File(path), null, false)
if (directoryListing != null) {
for (File child in directoryListing) {
groovyClassLoader.parseClass(child)
}
}
}
// See all the loaded classes
println(groovyClassLoader.loadedClasses)https://stackoverflow.com/questions/56801405
复制相似问题