groovy-language-server icon indicating copy to clipboard operation
groovy-language-server copied to clipboard

add support for gradle

Open 354651432 opened this issue 3 years ago • 3 comments

add support for gradle , lsp cannot find jar packages downloaded by gradle from maven repos

354651432 avatar Nov 09 '21 10:11 354651432

This is unlikely to happen any time soon. In the meantime, the groovy.classpath setting can be used to add jar packages.

joshtynjala avatar Nov 09 '21 17:11 joshtynjala

only can add all dependencies one by one . i want a automatic solution

354651432 avatar Nov 10 '21 01:11 354651432

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

joshtynjala avatar Nov 10 '21 17:11 joshtynjala

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}"

lgranie avatar Dec 22 '22 13:12 lgranie