

Gradle环境变量那些事
source link: https://blog.bihe0832.com/gradle_properties.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

最近真的是多灾多难,搞各种杂七杂八。带来的现象就是要不停的切换项目和工程,因为网络策略的问题,不同的项目使用了网络代理也不一样。专门去看了下Gradle环境变量相关的内容,然后整理一下。
官方介绍:
-
官网地址:
https://docs.gradle.org/current/userguide/build_environment.html
-
核心内容:
Gradle provides multiple mechanisms for configuring behavior of Gradle itself and specific projects. The following is a reference for using these mechanisms. When configuring Gradle behavior you can use these methods, listed in order of highest to lowest precedence (first one wins): Command-line flags such as –build-cache. These have precedence over properties and environment variables. System properties such as systemProp.http.proxyHost=somehost.org stored in a gradle.properties file. Gradle properties such as org.gradle.caching=true that are typically stored in a gradle.properties file in a project root directory or GRADLE_USER_HOME environment variable. Environment variables such as GRADLE_OPTS sourced by the environment that executes Gradle. Aside from configuring the build environment, you can configure a given project build using Project properties such as -PreleaseType=final.
个人总结
和git的配置类似,gradle的配置有四份:
-
针对整个设备生效:
这部分配置保存在系统的环境变量中,一般都比较有限,例如
GRADLE_OPTS
、GRADLE_USER_HOME
等这些基础配置。 -
针对整个用户生效:
这部分配置保存在文件
$GRADLE_USER_HOME/gradle.properties
中,对于当前用户下的的所有项目都适用。 -
针对整个项目生效:
这部分配置保存在对应项目根目录的文件
gradle.properties
中,这里的配置仅仅针对当前项目有效。 -
针对某次执行生效
这部分配置在执行命令时通过参数传入,这里的配置仅仅对当次执行生效
在实际项目中,用到的基本是下面三份配置,这三份配置的优先级关系是 命令行高于项目高于全局 。
具体使用
-
在
$GRADLE_USER_HOME/gradle.properties
中添加所有项目通用的内容,例如网络代理,例如插件发布的密钥等私有配置,这样其余项目不再需要设置 -
在项目根目录的文件 ` gradle.properties `中添加项目相关的配置,例如是否使用NDK等
-
在命令行中使用一些临时命令,例如–refresh-dependencies –no-daemon等
注意事项:
-
可以通过
./gradlew properties
命令查看项目的所有属性 -
对于开启了daemon的项目,当修改了gradle.properties的配置后,建议执行下面的命令更新一下配置,否则因为缓存,修改并不会及时生效:
./gradlew --refresh-dependencies --no-daemon
Recommend
-
55
原创 环境变量PATH which 查看绝对路径which ls查看ls的绝对路径[root@localhost ~]# which lsalias ls='ls --color=auto'
-
49
系统层次:/etc/下的文件用户层次:用户家目录下的文件系统层次下面的/etc/profile和/etc/bashrc最好不要乱动。如果我们想要添加变量就添加到用户目录下的.bash_profile或者.bashrc.和source一样,自动加载配置文件里面的一些配置~/.bash_logout定义用户退出时做的...
-
11
如何抓住消费行业变量?那些增长最快品牌的秘密黄海播客:疯投圈/得到:中国消费报告/ 公众号:黄海的消费业观察
-
12
[本文结构] 因为墙以及不同开发者的环境的原因,经常会出现clone了一个开源项目以后无法运行的情况,因此专门整理了个人的开源项目在引用或者运行时一些通用的注意事项,其实所...
-
17
[本文结构] Gradle 插件 这是截至目前在使用Gradle的过程中遇到的最大的坑。目前gradle的Android插件官方提供了两个版本:标准版本和实验性版本。而实验性版...
-
3
BASH自身信息 BASH / SHELL BASH 和 SHELL 变量记录的是当前shell的路径,linux上通常这两个变量的值都是/bin/bash. 这两者的区别在于,不是所有的shell都有定义 BASH 变量,但一定有定义 SHELL
-
8
要做个 Entry Task ,兴奋地配置了个 Java 的环境,没想到踩了这么多坑。 Plugin was not found in any of the following sources
-
7
Go语言map类型变量背后的那些事儿 三月 15, 2022 0 条评论
-
1
C语言全局变量那些事儿 浏览:3601次 出处信息 (感谢网友
-
11
Android入门第14天-AndroidStudio本机开发环境中gradle、sdk以及AVD目录的迁移 ...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK