I am trying to get coc-java to work in an environment where I don't have internet access. I generated my setup with internet access and transferred it to the offline environment, but when I open a java file and do :CocCommand workspace.showOutput
and choose coc-java
, I get a stacktrace beginning with Cannot download published Gradle versions. at org.eclipse.buildship.core.internal.util.gradle.PublishedGradleVersions.downloadVersionInformation(PublishedGradleVersions.java:165)
...Caused by: java.net.UnknownHostException: services.gradle.org
. I have gradle 7.4.2 already installed, and have the following settings in ~/.vim/coc-settings.json
:
"java.enabled" : true,
"java.autobuild.enabled": true,
"java.codeGeneration.generateComments": true,
"java.implementationsCodeLens.enabled": true,
"java.referencesCodeLens.enabled": true,
"java.completion.enabled" : true,
"java.foldingRange.enabled" : true,
"java.format.comments.enabled" : true,
"java.format.enabled" : true,
"java.format.onType.enabled" : true,
"java.home" : "/usr/java/jdk-11.0.2",
"java.import.gradle.enabled": true,
"java.import.gradle.offline.enabled": true,
"java.import.gradle.home": "/home/me/.opt/gradle/gradle-7.4.2",
"java.import.gradle.user.home": "/home/me/.gradle",
"java.import.gradle.version": "7.4.2",
"java.import.gradle.wrapper.enabled": false,
"java.import.maven.enabled": true,
"java.progressReports.enabled" : false,
"java.trace.server": "verbose",
"java.configuration.runtimes": [
{
"name": "JavaSE-11",
"path": "/usr/java/jdk-11.0.2",
"default": true
}
]
The coc-java docs says this about java.import.gradle.home
: Use Gradle from the specified local installation directory or GRADLE_HOME if the Gradle wrapper is missing or disabled and no 'java.import.gradle.version' is specified.
I've tried removing java.import.gradle.version
as well, but same issue occurs.
Given that the stacktrace mentions eclipse buildship, I've tried Googling how to change eclipse/buildship settings, but haven't been able to find out how to configure offline settings, if that's even possible. Has anyone been able to get coc-java to work offline with gradle?
Place the gradle-bin zip file in $GRADLE_USER_HOME/wrapper/dists/gradle-<some-version>-bin/<some-hash>/
I finally managed to hack my way around it. Even with the two properties set in coc-settings.json
:
"java.import.gradle.offline.enabled": true,
"java.import.gradle.wrapper.enabled": false,
... It still seemed to be trying to fetch gradle-7.1.1 from services.gradle.org
. After taking a look in $GRADLE_USER_HOME
, I noticed a wrapper
directory, despite never using gradle-wrapper for anything, so I dug deeper. After a lot of playing around, I managed to get it to work by taking a gradle-7.4.2-bin.zip
file I already had and placing it in $GRADLE_USER_HOME/wrapper/dists/gradle-7.1.1-bin/f29rtwfnc96ub43tt7p47zsru/
. I'm not sure the significance of that hash value nor why it would point to version 7.1.1 of gradle, but after putting the zip file there and opening a java file, it proceeded to create the gradle-7.4.2
folder under that hash folder with everything needed underneath, and coc commands started to work!