1. 安装gradle并设置环境变量
2. 在maven项目根目录下运行如下命令即可
gradle init --type pom
3. 使用gradle打包(跳过测试)
gradle build -x test
4. 解决“运行gradle命令时报错: 错误: 编码GBK的不可映射字符”问题
在build.gradle中添加如下配置
//指定编译的编码
tasks.withType(JavaCompile){
options.encoding = "UTF-8"
}
5. 指定阿里的中央仓库
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public" }
}
6. 使用init.gradle
init.gradle的作用
先来简单介绍一下init.gradle这个文件的作用。
它可以用来建立公司内部的配置,如定义公司内部的仓库地址。
它可以用来配置一些全局属性,比如配置持续集成服务器的地址等配置。
它可以用来提供构建所需要的用户的个人信息,如仓库或数据库的用户名和密码。
它可以用来定义开发者机器的环境,比如定义jdk安装在什么位置,android sdk安装在什么位置等等。
最重要的功能之一,它可以用来注册一些监听器。比如监听Gradle事件的发生,做一些额外的操作,例如需要对某个项目构建前和构建后做一些操作,又例如对项目的依赖做检测,检测是否含有snapshot包,在release构建中一般来说是禁止依赖snapshot包的,所以这时候就可以扔出一个异常。
重定向日志。我们可以将gradle默认的日志进行重定向,甚至我们可以不输出默认日志,自定义如何输出gradle产生的日志信息。
---------------------
转自:https://blog.youkuaiyun.com/sbsujjbcy/article/details/52079413
对所有项目生效,在${USER_HOME}/.gradle/
下创建init.gradle
文件
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'http://maven.aliyun.com/nexus/content/groups/public'
def ALIYUN_JCENTER_URL = 'http://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
}
}
}
---------------------
作者:提辖鲁
来源:优快云
原文:https://blog.youkuaiyun.com/lj402159806/article/details/78422953
版权声明:本文为博主原创文章,转载请附上博文链接!
7. 修复问题: gradlew.bat (and gradlew) SSLHandShakeException
错误信息:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certificati
on path to requested target
解决方法: 编辑当前项目下的./gradle/wrapper/gadle-wrapper.properties,
将https改成http
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
distributionUrl=http\://services.gradle.org/distributions/gradle-4.7-bin.zip