3

Environment: Linux + JDK 11 + Gradle 5.0 I have several gradle projects which must build from sources without Internet connection/ For example this one git clone --depth 1 --branch 3.0.0 https://github.com/bobbylight/RSyntaxTextArea.git for that first of all I built this project online then copy ~/.gradle to $PROJECT_DIR/grdl , next I want to test this build offine. I perform gradle --stop , clear whole ~/.gradle directory then turn off Internet and run following script:

cp -r ./grdl/* ~/.gradle
cd RSyntaxTextArea
gradle --offline clean build

And everything builds good until I move these files to a different Linux+JDK11+Gradle 5.0 offline machine. When I run same script there I have following errors:

./build.sh
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':RSyntaxTextArea'.
> Could not resolve all artifacts for configuration ':RSyntaxTextArea:classpath'.
   > Could not download coveralls-gradle-plugin.jar (org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.8.2): No cached version available for offline mode
   > Could not download httpmime.jar (org.apache.httpcomponents:httpmime:4.3): No cached version available for offline mode
   > Could not download org.eclipse.jgit.jar (org.eclipse.jgit:org.eclipse.jgit:3.6.0.201412230720-r): No cached version available for offline mode
   > Could not download http-builder.jar (org.codehaus.groovy.modules.http-builder:http-builder:0.7.1): No cached version available for offline mode
   > Could not download httpclient.jar (org.apache.httpcomponents:httpclient:4.3): No cached version available for offline mode
   > Could not download jsch.jar (com.jcraft:jsch:0.1.50): No cached version available for offline mode
   > Could not download JavaEWAH.jar (com.googlecode.javaewah:JavaEWAH:0.7.9): No cached version available for offline mode
   > Could not download json-lib-jdk15.jar (net.sf.json-lib:json-lib:2.3): No cached version available for offline mode
   > Could not download nekohtml.jar (net.sourceforge.nekohtml:nekohtml:1.9.16): No cached version available for offline mode
   > Could not download xml-resolver.jar (xml-resolver:xml-resolver:1.2): No cached version available for offline mode
   > Could not download httpcore.jar (org.apache.httpcomponents:httpcore:4.3): No cached version available for offline mode
   > Could not download commons-beanutils.jar (commons-beanutils:commons-beanutils:1.8.0): No cached version available for offline mode
   > Could not download commons-logging.jar (commons-logging:commons-logging:1.1.3): No cached version available for offline mode
   > Could not download commons-codec.jar (commons-codec:commons-codec:1.6): No cached version available for offline mode
   > Could not download commons-collections.jar (commons-collections:commons-collections:3.2.1): No cached version available for offline mode
   > Could not download ezmorph.jar (net.sf.ezmorph:ezmorph:1.0.6): No cached version available for offline mode
   > Could not download commons-lang.jar (commons-lang:commons-lang:2.4): No cached version available for offline mode
   > Could not download xercesImpl.jar (xerces:xercesImpl:2.9.1): No cached version available for offline mode
   > Could not download xml-apis.jar (xml-apis:xml-apis:1.3.04): No cached version available for offline mode

I have four of five gradle projects with similar problem. Surprisingly, one went offline fine on both machines, this one - git clone --depth 1 --branch 0.27 https://github.com/JFormDesigner/FlatLaf.git . I think that I don't understand gradle cache properly. Could you help me to build gradle projects without Internet? It could be any version of Gradle but I tied to Linux + JDK 11.

2 Answers2

4

I think you are hitting this issue: https://github.com/gradle/gradle/issues/1338

That is, cache items are non relocatable. Copying the whole ~/.gradle folder may not be enough, especially if ~ resolves to a different path than in the original machine (i.e. different user). The full path needs to be exactly the same (with Gradle 5.0).

The issue suggests however that version 6.1 makes the cache relocatable, so perhaps you'll have more luck with a recent version (7.2 is the latest at this point in time).

EDIT: The release notes and these docs confirm that the cache can be copied across deployments as of version 6.1.1.

cornuz
  • 2,678
  • 18
  • 35
  • Username is really different, but I can't test your idea, because Gradle v 6.1 said "> Plugin with id 'osgi' not found." – Ekaterina Ivanova iceja.net Sep 13 '21 at 14:31
  • @EkaterinaIvanovaiceja.net In any case versions before 6.1 are guaranteed not to work if the full path is different. Have you tried to copy only the `~/.gradle/cache` subfolder, instead of everything? That might solve your issue with the plugin. – cornuz Sep 13 '21 at 14:43
  • @crnuz for now I can't build even online with gradle 6.1, 7.2. The v 7.2. give me following error: "Could not find method testCompile() for arguments [junit:junit:4.12] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler." – Ekaterina Ivanova iceja.net Sep 13 '21 at 14:59
  • @EkaterinaIvanovaiceja.net, perhaps version 7 is giving you some Java incompatibility issue. Have you tried with an intermediate version? Say 6.8? First try it in online mode with a fresh `~/.gradle`. If it works, try copying only the cache folder into an offline deployment (also with `~/.gradle` bootstrapped by the version you are using). – cornuz Sep 13 '21 at 15:35
  • Gradle 6.8 said "> Plugin with id 'osgi' not found." the same is v 6.1 – Ekaterina Ivanova iceja.net Sep 13 '21 at 15:55
  • @EkaterinaIvanovaiceja.net see https://stackoverflow.com/questions/60864317/plugin-with-id-osgi-not-found (the links contained appears to be broken, but hopefully the thread can help you find the solution). This plugin is deprecated. Do you use it explicitly? If so, can you not use it? – cornuz Sep 13 '21 at 15:59
  • @EkaterinaIvanovaiceja.net: https://docs.gradle.org/current/userguide/upgrading_version_5.html#the_osgi_plugin_has_been_removed – cornuz Sep 13 '21 at 16:07
0

One solution that worked for me is to copy the $'username'/.gradle/caches/modules-2/files-2.1 folder

This contains all the libraries that gradle has cached and could be reused. I think this was not possible with gradle versons < gradle 6.1.

After copying the files-2.1 folder you can sync the gradle project with the offline mode toggled on intellij/eclipse.

If it still does not work copy the entire caches folder.

Memli Restelica
  • 228
  • 2
  • 7