groovy-language-server
groovy-language-server copied to clipboard
add support for gradle
add support for gradle , lsp cannot find jar packages downloaded by gradle from maven repos
This is unlikely to happen any time soon. In the meantime, the groovy.classpath
setting can be used to add jar packages.
only can add all dependencies one by one . i want a automatic solution
Yes, I understand that you want an automatic solution. That's not possible yet, so I gave you the best manual workaround that's available right now. 😺
I modify GroovyLanguageServer.main and add a constructor :
public static void main(String[] args) {
InputStream systemIn = System.in;
OutputStream systemOut = System.out;
// redirect System.out to System.err because we need to prevent
// System.out from receiving anything that isn't an LSP message
System.setOut(new PrintStream(System.err));
// Pass PROJECT_CLASSPATH to the server
GroovyLanguageServer server = new GroovyLanguageServer(args);
Launcher<LanguageClient> launcher = Launcher.createLauncher(server, LanguageClient.class, systemIn, systemOut);
server.connect(launcher.getRemoteProxy());
launcher.startListening();
}
private GroovyServices groovyServices;
// New constructor
public GroovyLanguageServer(String[] args) {
CompilationUnitFactory cuf = new CompilationUnitFactory();
cuf.setAdditionalClasspathList(Arrays.asList(args[0].split(":")));
this.groovyServices = new GroovyServices(cuf);
}
I build PROJECT_CLASSPATH with gradle-classpath (https://github.com/dansomething/gradle-classpath) and pass it to groovy-language-server like this :
PROJECT_CLASSPATH=$(/opt/gradle-classpath-1.2.0/bin/gradle-classpath --gradle-home="/opt/gradle-7.5.1")
java -jar /opt/groovy-language-server/build/libs/groovy-language-server-all.jar "${PROJECT_CLASSPATH}"