Windows安装Gradle
如果你没有安装maven的话,建议先安装maven,再安装Gradle。
不要用什么Gradle Wrapper下载慢,直接用Gradle就好。
安装
下载Gradle,解压,添加系统环境变量
GRADLE_HOME,D:\javatools\gradle-6.2.2
GRADLE_USER_HOME,D:\javatools\maven_repository
添加到path
%GRADLE_HOME%\bin\
注意了,gradle的默认仓库路径为用户目录下的.gradle
目录,gradle并没有像maven那样提供配置文件,若要修改默认仓库路径,我们可以设置环境变量GRADLE_USER_HOME
。GRADLE_USER_HOME
仓库路径可以配置跟maven一样。
检查安装
$ gradle -v
Gradle 6.2.2
加速下载
在USER_HOME/.gradle/下创建init.gradle
文件
allprojects {
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/nexus/content/repositories/jcenter'
all {
ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}
linux安装
$ mkdir /opt/gradle
$ unzip -d /opt/gradle gradle-6.2.2-bin.zip
$ ls /opt/gradle/gradle-6.2.2
LICENSE NOTICE bin getting-started.html init.d lib media
添加到path
$ export PATH=$PATH:/opt/gradle/gradle-6.2.2/bin
Eclipse
这里用的Eclipse是2019-12javaEE 版,不用安装Gradle插件。
Offline Mode,先打上钩。非常关键的一步!!!
File-New-Other,输入gradle。
输入项目名netty_study,点next。
点next
点next
这个时候创建出来的项目有可能是报错的,在build.gradle文件中加入以下代码
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/public/' }
mavenLocal()
mavenCentral()
}
}
保存。Window-Preferences-Gradle。去掉Offline Mode的钩。
File-Restart,重启Eclipse。
IDEA
跟Eclipse差不多。
仓库
代理的仓库列表
仓库名称 | 阿里云仓库地址 | 阿里云仓库地址(老版) | 源地址 |
---|---|---|---|
central | https://maven.aliyun.com/repository/central | https://maven.aliyun.com/nexus/content/repositories/central | https://repo1.maven.org/maven2/ |
jcenter | https://maven.aliyun.com/repository/public | https://maven.aliyun.com/nexus/content/repositories/jcenter | http://jcenter.bintray.com/ |
public | https://maven.aliyun.com/repository/public | https://maven.aliyun.com/nexus/content/groups/public | central仓和jcenter仓的聚合仓 |
https://maven.aliyun.com/repository/google | https://maven.aliyun.com/nexus/content/repositories/google | https://maven.google.com/ | |
gradle-plugin | https://maven.aliyun.com/repository/gradle-plugin | https://maven.aliyun.com/nexus/content/repositories/gradle-plugin | https://plugins.gradle.org/m2/ |
spring | https://maven.aliyun.com/repository/spring | https://maven.aliyun.com/nexus/content/repositories/spring | http://repo.spring.io/libs-milestone/ |
spring-plugin | https://maven.aliyun.com/repository/spring-plugin | https://maven.aliyun.com/nexus/content/repositories/spring-plugin | http://repo.spring.io/plugins-release/ |
grails-core | https://maven.aliyun.com/repository/grails-core | https://maven.aliyun.com/nexus/content/repositories/grails-core | https://repo.grails.org/grails/core |
apache snapshots | https://maven.aliyun.com/repository/apache-snapshots | https://maven.aliyun.com/nexus/content/repositories/apache-snapshots | https://repository.apache.org/snapshots/ |
全局配置
Gradle全局
对所有项目生效,在USER_HOME/.gradle/下创建init.gradle
文件
allprojects {
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/nexus/content/repositories/jcenter'
all {
ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
}
}
maven {
url ALIYUN_REPOSITORY_URL
url ALIYUN_JCENTER_URL
}
}
}
maven全局
maven在USER_HOME/.m2
目录下放置settings.xml
文件。可以从maven安装目录的conf/settings.xml
拷贝过来。
先配置好maven安装目录的conf/settings.xml
文件,再拷贝到.m2
目录。
<!--maven本地jar存放位置-->
<localRepository>D:\maven_repository</localRepository>
<!--镜像仓库 -->
<mirrors>
<mirror>
<id>aliyunmaven</id>
<mirrorOf>*</mirrorOf>
<name>aliyunmaven</name>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
</mirrors>