groovy-guru
groovy-guru copied to clipboard
Automatic dependency/classpath handling with maven
Good work so far, this extension looks promising.
But, I have a maven Groovy project (Jenkins shared library) and there are around 14000 files in the maven repo cache with direct and indirect dependencies of various versions of Jenkins and their plugins. It would be nice if adding every JAR file would not be required and the extension would detect maven and use its repo cache and searched it for the required JARs.
Right now I am facing many java.lang.NoClassDefFoundError or squiggly lines everywhere. All in all I think it's around 10-50 JARs, but it's cumbersome to adjust the list in extension settings as soon as a dependency tree changes versions.
Let me take this issue to the maintainers of the groovy language server, as that is where the logic for the jars is held.
@mdealer
You said: "It would be nice if adding every JAR file would not be required"
You can also just set a directory, instead of each individual jar file. Like this in your vscode settings:
"groovy.classpath": [
"/home/shadycuz/repos/dsty/jenkins-std-lib/build/dependencies"
],
@mdealer
You said: "It would be nice if adding every JAR file would not be required"
You can also just set a directory, instead of each individual jar file. Like this in your vscode settings:
"groovy.classpath": [ "/home/shadycuz/repos/dsty/jenkins-std-lib/build/dependencies" ],
Is it supposed to recurse into subdirectories? I tried and kept getting the same errors. It only seemed to load the immediate JARs from that directory.
Correct, It only reads jars from the parent directories. Would recursion fix the issue for you?
Correct, It only reads jars from the parent directories. Would recursion fix the issue for you?
I don't think so, because maven cache contains many different versions of everything. Versions are project specific and defined in the pom.xml.
oh I see @mdealer
Thanks
I was also struggling with this (still am!) - I am trying to setup a groovy scripting environment for my java based application framework in VS Code.
I use gradle for dependency management. I have a working gradle groovy project that builds the code (on the command line and in vscode: gradle compileGroovy
completes as expected) but the dependencies are not recognized in the code editor, with lots of unable to resolve class xxx
errors for my imports.
I thought I could automatically update the groovy.classpath
setting in my workspace setttings.json
directly in my gradle file like this, basically adding all the gradle dependencies to the extension classpath:
task updateGroovyClasspath {
doLast {
def javaDeps = configurations.runtimeClasspath.files.collect { "$it" }
def f = file("../.vscode/settings.json")
def builder = new JsonBuilder(new JsonSlurper().parse(f))
builder.content['groovy.classpath'] = javaDeps
f.write(builder.toPrettyString())
}
}
compileGroovy {
dependsOn updateGroovyClasspath
}
This works (at least I see lots of dependencies now in the settings), but the unable to resolve class xxx
errors persist. Should this work? Am I missing something? Thanks.