FabricMC / fabric-loom

Gradle build system plugin used to automate the setup of a minecraft mod development environment.
MIT License
242 stars 212 forks source link

Loom persistent project-level cache does not respect `--project-cache-dir` #1203

Open lukebemish opened 1 month ago

lukebemish commented 1 month ago

Gradle has a --project-cache-dir argument that allows it to use a different folder than .gradle as the root-project-level persistent-cache:

--project-cache-dir                Specify the project-specific cache directory. Defaults to .gradle in the root project directory.

This can be useful when testing stuff that writes things there and wanting to compare what it writes accross multiple runs with some differing state, for debugging reasons or otherwise. However, loom does not respect this and always uses .gradle (see the logic here). The correct approach seems to be to obtain this directory from the StartParameter via project.gradle.startParameter.projectCacheDir.

Note, however, that there is no guarantee that the cache directory in question is located in any particular way relative to the root project directory (and really, no reason to make such an assumption in general either)! So obeying this would require re-thinking loom's current approach of one-persistent-cache-folder-per-subproject, which is not something gradle does at all -- basically, the .gradle folder loom creates in subprojects is kinda random and not actually something gradle ever makes. Perhaps instead, loom could store a folder per subproject inside the persistent cache dir of the root project, and so be able to respect this option? That is, instead of

rootProject
- .gradle
  - loom-cache
    - <stuff>
- subproject
  - .gradle
    - loom-cache
      - <stuff>

It would be something like

.whatever-the-persistent-cache-is
- loom-cache
  - <stuff>
  - subproject
    - <stuff>