How to get the dependencies jars in one place?

Although I prefer to work from desktop, due to the huge power cuts I have to work on the same projects from laptop / battery / without connection. Also, due to design and price tradeoffs, the laptop has longer battery life but smaller SSD space.

As I learn new things, and even help other people reviewing their code, there are more dependencies to fetch. I find it very hard to make any project involving Gradle to work in that case.

What I need is to have all dependencies in one place and preferably substitution (like defaulting all Gradle 6.X.X. to installed 6.9.2). Okay, the latter I can set manually, but it’s very hard to copy the dependencies and reduce them to acceptable size.

I think of something like

  • one dedicated folder for dependencies (no caching duplicates for reducing space)
  • some incremental backup solution

Can I do this with Gradle?

  • I found an options stopping caching duplication (org.gradle.caching=false in gradle.properties ), but it seems I have to put it in every project.
  • Is there any way to make Gradle store jar dependencies like Maven, in concise structure? Or maybe force it to use Maven repository?

P.S. Power cut again.

I’m not sure what you are asking about actually.
Gradle is working perfectly fine even without internet connection as long as all dependencies you need are in the cache already.

What I need is to have all dependencies in one place

one dedicated folder for dependencies

Is there any way to make Gradle store jar dependencies like Maven

That’s exactly what Gradle does, they are downloaded to its dependencies cache that even works cross-project to not waste space.

like defaulting all Gradle 6.X.X. to installed 6.9.2

Just don’t use the Gradle wrapper of the project, but use gradle from the installed 6.9.2,
but actually you shouldn’t do that, as that might cause builds to fail or behave differently.
Gradle builds should always run using the wrapper to run with the exact version the build is designed for and known working with.
The dependencies cache even works cross-version as long as the cache structure didn’t change, which shouldn’t be the case in minor updates usually.

I found an options stopping caching duplication (org.gradle.caching=false in gradle.properties ), but it seems I have to put it in every project

That property has nothing to do with dependencies cache. This option is about task output caching. And actually false is its default, so when you didn’t have that enabled in some way, the property is actually a no-op.

So I’m really unsure what you are asking about.
What I read, roughly summarized, is “how can I make Gradle behave exactly like it does by default”, so I probably misunderstood something.

As I say, I work in rather difficult environment, with frequent power cuts.
I prefer to work at the desktop computer with 2 displays, but when power is cut, I have to move to laptop.
When the desktop loses power, I have a few minutes to copy something to flash drive and take with me. But by the time the laptop is actually offline.

Perhaps it would be less of a problem if I wasn’t helping other people and learning. Sometimes I work with other people, and have a look at code at Github. Most of the times I work with Java, Junit, Selenide, but I started to look at Kotlin and Android.

  • I used more to Maven projects,
  • And I review code of the people working with Maven and I know where it stores the dependencies, so my first hope (in vain) was that Gradle copies what I need to common Maven repo. Nope.
  • I looked at size of the Gradle folder, and found it like over 8 Gb… kind of much more that I wanted (my .m2 folder is like 2.5 Gb now).
  • I looked at the wrappers, and found there 6.3, 6.6.1, 6.9, 7.4, 7.4.2 … kind of more than I thought.
  • I copied some jars manually, but next came problem with the Gradle plugins… they seem not being shared between wrappers.
  • I run Windows Clonespy utility looking for the duplicates, and found in Gradle folder duplicate jars over 360Mb in size.

Basically I want to minimize Gradle footprint as much as possible – for the purpose of moving it offline between machines for working offline when power is cut. I totally understand that wrappers are configured for a particular setup, but I’m willing to take the risk: I win 230 Mb of space removing single 7.4 wrapper.

An ideal for me solution would be to force Gradle to store all jars to .m2 {I have read the documentation that Gradle don’t trust Maven, but again, I’m willing to take the risk}.

The second part is that I’m looking for a solution to get all jar dependencies for a particular project in one folder (IntelliJ build system seems to be able to do that).

I wonder if Gradle has means for minimizing the footprint and getting all dependencies in one compact place.

  • And I review code of the people working with Maven and I know where it stores the dependencies, so my first hope (in vain) was that Gradle copies what I need to common Maven repo. Nope.

Of course not, it is Gradle, not Maven.
There are several good reasons not to do that.

  • I looked at size of the Gradle folder, and found it like over 8 Gb… kind of much more that I wanted (my .m2 folder is like 2.5 Gb now).

That’s because Gradle is much better than Maven in providing reproducible reliable builds and avoiding work. This means for example that a build defines the exact Gradle version to build it and when the one running the build is using the wrapper scripts as exepected, this exact Gradle version is used and the build cannot change behavior or break just becuase a different Gradle version is used to run it like with Maven. If you use the Maven wrapper (basically a copy of the concept from Gradle, you will also have multiple Maven versions in your .m2 directory). And it also means, that Gradle has much more caches and things in its GRADLE_USER_HOME, so there is additional data in it than just the JARs.
Also maybe the Gradle builds you used had more and different dependencies than the Maven builds you used and thus have more data in it. In the GRADLE_USER_HOME are also things you shouldn’t care to copy or actually shouldn’t copy because they are not relocatable. You should for example omit the daemon directory, as it only contains daemon logs and lock files.
And from the caches, you should probably only copy over what is documented at Understanding dependency resolution, which should basically be the JARs you were after.

  • I looked at the wrappers, and found there 6.3, 6.6.1, 6.9, 7.4, 7.4.2 … kind of more than I thought.

Well, if you run many different projects that all use different versions, you have the different distributions there (not wrappers).
Of course you can decide not to use the Gradle wrapper to run the builds, but any installed Gradle version, but that might easily break the build or cause unexpected behavior, sometimes sneaky.

  • I copied some jars manually, but next came problem with the Gradle plugins… they seem not being shared between wrappers.

Of course they are. Well, the built-in plugins are built-in in each Gradle version of course.
But all 3rd party plugins are in the dependency cache like any other dependency and also reused across versions unless there are variants of the plugin optimized for different Gradle versions, but that is very seldomly the case in the wild.

  • I run Windows Clonespy utility looking for the duplicates, and found in Gradle folder duplicate jars over 360Mb in size.

Well, you would need to tell which to get any sane recommendation.
But I guess those are the jars in the distributions and for those there is of course not deduplication.
The cached dependency jars will not be duplicates.

An ideal for me solution would be to force Gradle to store all jars to .m2 {I have read the documentation that Gradle don’t trust Maven, but again, I’m willing to take the risk}.

That would not be ideal. That would simply not work at all and will probably never be possible for various reasons.

The second part is that I’m looking for a solution to get all jar dependencies for a particular project in one folder (IntelliJ build system seems to be able to do that).

Well, the dependencies for all projects are in one folder, the cache explained above.
If you want separate for each project, you could configure different GRADLE_USER_HOME for the different projects, then only the dependencies of that project land in the respective cache, but then you have even less deduplication, i. e. none cross-project.

If you want the dependencies for a project in one directory, you need to write a copy task that copies the dependencies into that directory, but what would that help? You would then also have to change the build to take the dependencies from there. And maintain those changes, … You certainly don’t want to do that, especially for foreign projects.

I wonder if Gradle has means for minimizing the footprint and getting all dependencies in one compact place.

As the GRADLE_USER_HOME is not designed to be shared and relocated except for particular parts, I don’t think there is any option to minimize it.