gradle的安装,配置阿里云镜像加速

痛定思痛。 2022-11-12 12:53 749阅读 0赞

下载gradle
在这里插入图片描述
下载后解压缩

第一步、配置阿里云镜像加速地址

在init.d目录中创建一个文件,文件名如下

  1. init.gradle

粘贴下面的内容进入到这个文件

  1. gradle.projectsLoaded {
  2. rootProject.allprojects {
  3. buildscript {
  4. repositories {
  5. def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
  6. def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
  7. def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
  8. all { ArtifactRepository repo ->
  9. if (repo instanceof MavenArtifactRepository) {
  10. def url = repo.url.toString()
  11. if (url.startsWith('https://jcenter.bintray.com/')) {
  12. project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
  13. println("buildscript ${repo.url} replaced by $JCENTER_URL.")
  14. remove repo
  15. }
  16. else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
  17. project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
  18. println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
  19. remove repo
  20. }
  21. else if (url.startsWith('https://repo1.maven.org/maven2')) {
  22. project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
  23. println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
  24. remove repo
  25. }
  26. }
  27. }
  28. jcenter {
  29. url JCENTER_URL
  30. }
  31. google {
  32. url GOOGLE_URL
  33. }
  34. maven {
  35. url NEXUS_URL
  36. }
  37. }
  38. }
  39. repositories {
  40. def JCENTER_URL = 'https://maven.aliyun.com/repository/jcenter'
  41. def GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
  42. def NEXUS_URL = 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
  43. all { ArtifactRepository repo ->
  44. if (repo instanceof MavenArtifactRepository) {
  45. def url = repo.url.toString()
  46. if (url.startsWith('https://jcenter.bintray.com/')) {
  47. project.logger.lifecycle "Repository ${repo.url} replaced by $JCENTER_URL."
  48. println("buildscript ${repo.url} replaced by $JCENTER_URL.")
  49. remove repo
  50. }
  51. else if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
  52. project.logger.lifecycle "Repository ${repo.url} replaced by $GOOGLE_URL."
  53. println("buildscript ${repo.url} replaced by $GOOGLE_URL.")
  54. remove repo
  55. }
  56. else if (url.startsWith('https://repo1.maven.org/maven2')) {
  57. project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL."
  58. println("buildscript ${repo.url} replaced by $REPOSITORY_URL.")
  59. remove repo
  60. }
  61. }
  62. }
  63. jcenter {
  64. url JCENTER_URL
  65. }
  66. google {
  67. url GOOGLE_URL
  68. }
  69. maven {
  70. url NEXUS_URL
  71. }
  72. }
  73. }
  74. }

第二步、配置环境变量

让 gradle.bat 能全局调用

将bin目录配置进PATH
在这里插入图片描述


配置本地仓库的存储路径

在maven的配置文件中可以使用<localRepository>指定本地仓库地址,gradle则采用环境变量的方式指定本地仓库地址,环境变量名GRADLE_USER_HOME,值可以指定一个文件夹,例如创建一个repository
需要提取创建好这个文件夹,如下图
在这里插入图片描述
在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,749人围观)

还没有评论,来说两句吧...

相关阅读