Multi-Project cache conflicts

Hello,

I have a server application running in Eclipse and a client application running in Android studio. They both use Gradle for dependency management.

The problem is that I can’t have both Android Studio and Eclipse running at the same time, because they each compile their respective projects and in the process they seem to remove each other’s dependencies from the central gradle repository / cache.

How can I edit my .gradle files in each project so that the respective dependencies are stored in a project-local directory, rather than in a central location?

Many thanks

Unless your builds are doing very strange things, the central dependency cache is not cleared, so those builds should not influence in the way you describe. That would be ridiculous actually. I strongly assume that your problem is somewhere completely different.

If you really want to do what you asked for, you can just define different locations for the Gradle User Home, for example using environment variable GRADLE_USER_HOME, system property org.gradle.user.home, or -g or --gradle-user-home command line options. But you really shouldn’t need this and better find the real cause of your issues.

I found this in the [docs]
(Build Cache):
Gradle will periodically clean-up the local cache directory by removing entries that have not been used recently to conserve disk space.

removeUnusedEntriesAfterDays defaults to 7 days.

Could it be that when gradle builds the Android project, it sees that it hasn’t used before the libs used by the Eclipse project and so it removes them? The eclipse project is setup by a gradle plugin to reference libraries directly from the cache directory. So when libs are removed from the cache, it complains with errors as it can no longer reference those libs.

Anyway, for anyone else having the same problem, I was able to resolve the issue by adding the following in my settings.gradle:

buildCache {
    local {
        directory = new File(rootDir, '.gradle/build-cache')
        removeUnusedEntriesAfterDays = 180
    }
}

This moves the build-cache for the android project only, inside the project’s home directory

The build cache is absolutely irrelevant and any change you made should have had no impact to your issue. If you properly read the chapter, you see that the build cache caches task outputs of cacheable tasks, not dependencies.

What you have problem with is the dependency cache: Gradle User Manual: Version 7.4.2. it has a cleanup period of 30 days being unused and like with all caches, the cache knows the last access, not the project, so no, as long as you built the other project within the last 30 days, the build will not remove those cache entries.

ah yes, you are absolutely right, thanks for catching that.

So perhaps what’s happening is that I haven’t build the server project for > 30 days, and when I later build the android project, gradle removes my server dependencies. Am I getting this right?

I’m trying to figure out how to apply your suggestion on a per project basis, not system-wide. For example, setting environment variable GRADLE_USER_HOME would not work as it would affect both projects.

I tried adding the following lines in gradle.properties in the project root:

systemProp.org.gradle.user.home=./gradleProjectHome
org.gradle.user.home=./gradleProjectHome

systemProp.gradle.user.home=./gradleProjectHome
gradle.user.home=./gradleProjectHome

Then I do gradle build, however I don’t see my custom gradleProjectHome being created.

What am I doing wrong?

I don’t think you can set it from gradle.properties.
And I really, really think you should not set it different per project.
If you really want to do that, you probably have to modify the gradlew scripts, or have a wrapper script that calls the wrapper script with -g option.