Gradle8.5 Environment variables
The following environment variables are available for the gradle
command.
以下环境变量可用于gradle命令。
GRADLE_HOME
Installation directory for Gradle.
Can be used to specify a local Gradle version instead of using the wrapper.
You can add GRADLE_HOME/bin to your PATH for specific applications and use-cases (such as testing an early release for Gradle).
Gradle 的安装目录。
可用于指定本地 Gradle 版本,而不是使用包装器。
您可以针对特定的应用程序和用例(例如测试 Gradle 的早期版本)添加GRADLE_HOME/bin
到您的应用程序和用例的PATH(系统环境变量PATH)中。
JAVA_OPTS
Used to pass JVM options and custom settings to the JVM.
用于将 JVM 选项和自定义设置传递给 JVM。
GRADLE_OPTS
Specifies JVM arguments to use when starting the Gradle client VM.
The client VM only handles command line input/output, so it is rare that one would need to change its VM options.
The actual build is run by the Gradle daemon, which is not affected by this environment variable.
指定启动 Gradle 客户端虚拟机时要使用的 JVM 参数。
客户端 VM 仅处理命令行输入/输出,因此很少需要更改其 VM 选项。
实际构建由 Gradle 守护程序运行,该守护程序不受此环境变量的影响。
GRADLE_USER_HOME
Specifies the GRADLE_USER_HOME directory for Gradle to store its global configuration properties, initialization scripts, caches, log files and more.
Defaults to USER_HOME/.gradle if not set.
指定 Gradle 用于存储其全局配置属性、初始化脚本、缓存、日志文件等的目录。GRADLE_USER_HOME
如果未设置,则默认为。USER_HOME/.gradle
JAVA_HOME
Specifies the JDK installation directory to use for the client VM.
This VM is also used for the daemon unless a different one is specified in a Gradle properties file with org.gradle.java.home.
指定要用于客户端 VM 的 JDK 安装目录。
此虚拟机也用于守护进程,除非在 Gradle 属性文件中用org.gradle.java.home
指定了其他 VM。
GRADLE_LIBS_REPO_OVERRIDE
Overrides for the default Gradle library repository.
Can be used to specify a default Gradle repository URL in org.gradle.plugins.ide.internal.resolver.
Useful override to specify an internally hosted repository in case your company uses a firewall/proxy.
覆盖默认的 Gradle 库代码库。
可用在 org.gradle.plugins.ide.internal.resolver
中指定默认的 Gradle 代码库网址。
有用的覆盖,用于指定内部托管的存储库,以防您的公司使用防火墙/代理。
The following examples demonstrate how to use environment variables.
以下示例演示如何使用环境变量。
Example 1: Reading environment variables at configuration time:
示例 1:在配置时读取环境变量:
-
Kotlin
init.gradle.kts
文件// Using the Java API println(System.getenv("ENVIRONMENTAL"))
settings.gradle.kts
文件// Using the Java API println(System.getenv("ENVIRONMENTAL")) // Using the Gradle API, provides a lazy Provider<String> println(providers.environmentVariable("ENVIRONMENTAL").get())
build.gradle.kts
文件// Using the Java API println(System.getenv("ENVIRONMENTAL")) // Using the Gradle API, provides a lazy Provider<String> println(providers.environmentVariable("ENVIRONMENTAL").get())
-
Groovy
init.gradle
文件// Using the Java API println System.getenv('ENVIRONMENTAL')
settings.gradle
文件// Using the Java API println System.getenv('ENVIRONMENTAL') // Using the Gradle API, provides a lazy Provider<String> println providers.environmentVariable('ENVIRONMENTAL').get()
build.gradle
文件// Using the Java API println System.getenv('ENVIRONMENTAL') // Using the Gradle API, provides a lazy Provider<String> println providers.environmentVariable('ENVIRONMENTAL').get()
Example 2: Reading environment variables for consumption at execution time:
示例 2:读取环境变量以在执行时使用:
- Kotlin
build.gradle.kts
文件
tasks.register<PrintValue>("printValue") {
// Using the Gradle API, provides a lazy Provider<String> wired to a task input
inputValue = providers.environmentVariable("ENVIRONMENTAL")
}
- Groovy
build.gradle
文件
tasks.register('printValue', PrintValue) {
// Using the Gradle API, provides a lazy Provider<String> wired to a task input
inputValue = providers.environmentVariable('ENVIRONMENTAL')
}