Search code examples
gradlegradlew

Issue in copying gradle cache to an offline system


I have a laptop in which I am running a Gradle project using the wrapper gradlew. The dependencies for this project can only be downloaded from our organization's network. My testing team wants to test the project outside our organization network, hence I cannot download the dependencies. So I have copied the entire ".gradle" folder from C:\\Users\\MyUserName of my machine to the C:\\Users\\Admin of the other system. And I run, gradlew --offline. But I get an error stating that the cache has not been found, though the JARS are present in the ".gradle" directory. Is there anything that I am missing?


Solution

  • The gradle cache folder is not supposed to be copyied to different directories as some paths stored in there are referenced by absolute path. You would need to run your build at least from with gradle user home C://Users/Admin to get it working on your offline system later with --offline

    I'd use a dedicated folder for that (like C:/gradle-cache) and set GRADLE_USER_HOME to point to that directory or use the -g option in gradle to specify the gradle cache folder.

    There's a bug in Gradle at the moment that prevents the Wrapper to respect the -g option (https://github.com/gradle/gradle/issues/1895) . So as you seem to use the wrapper, you probably should go with the GRADLE_USER_HOME environment variable.

    Then on your target system you copy the cache to C:/gradle-cache again and also set GRADLE_USER_HOME and your offline build should work.