groovy-guru icon indicating copy to clipboard operation
groovy-guru copied to clipboard

Automatic dependency/classpath handling with maven

Open mdealer opened this issue 3 years ago • 7 comments

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.

mdealer avatar Jan 28 '22 10:01 mdealer

Let me take this issue to the maintainers of the groovy language server, as that is where the logic for the jars is held.

shadycuz avatar Feb 10 '22 14:02 shadycuz

@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"
    ],

shadycuz avatar Feb 10 '22 15:02 shadycuz

@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.

mdealer avatar Feb 10 '22 16:02 mdealer

Correct, It only reads jars from the parent directories. Would recursion fix the issue for you?

shadycuz avatar Feb 10 '22 22:02 shadycuz

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.

mdealer avatar Feb 11 '22 10:02 mdealer

oh I see @mdealer

Thanks

shadycuz avatar Feb 12 '22 13:02 shadycuz

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.

turchinc avatar May 30 '24 07:05 turchinc