gradle - Gradle: automatically choose GRADLE_HOME depending on the project
问题描述
At my job we use gradle, so on my laptop I have a ~/.gradle/init.d
folder which contains the init scripts that define our enterprise-wide configuration, such as the URL of the local repository, docker publishing rules, checkstyle rules, etc.
I want to use gradle for a personal project, so I don't want to use any of these init scripts. Here are the ideas I have come up with so far:
- Rename
~/.gradle
to~/.gradle-work
, create~/.gradle-personal
, and then symlink~/.gradle
to-work
or-personal
depending on what I'm doing. - Have
~/.gradle
as my personal gradle settings, and create another gradle folder~/dev/work/.gradle
with all my work init scripts. Make sure$GRADLE_HOME
is set to~/dev/work/.gradle
when running gradle for any work projects. - Some variant of 2 where gradle will automatically use
~/dev/work/.gradle
if it detects that the project is in the~/dev/work/
folder.
Option 1 feels quite clumsy. Option 2 feels very tedious to have to set or unset an environment variable whenever I want to use gradle. Ideally I would like something like option 3 where I don't have to do any fiddling around whenever I change between personal or work projects. Is this possible? Or is there another solution that could solve my problem?