- gradle下载地址:http://services.gradle.org/distributions/
从官网下载gradle后,解压,然后配置环境变量GRADLE_HOME,并将%GRADLE_HOME%/bin添加到path中,通过命令
gradle –v 测试是否安装成功,如果显示gradle版本信息,则安装成功
-
settings.gradle设置多工程依赖
rootProject.name = ‘activeMq’
include ‘domain’
include ‘service’
include ‘war’ -
build.gradle常用配置:
Java插件定义 Apply plugin: ’java’
添加Maven仓库 :
Repositories{
mavenCentral()
maven{
url ‘http://repo.sprinig.io/milestone/’
}
}
添加依赖:
dependencies {
compile group: ‘commons-collections’, name: ‘commons-collections’, version: ‘3.2’
testCompile group: ‘junit’, name: ‘junit’, version: ‘4.+’
}
compile:
编译范围依赖在所有的 classpath 中可用,同时它们也会被打包
runtime:
runtime 依赖在运行和测试系统的时候需要,但在编译的时候不需要。比如,你可能在编译的时候只需要 JDBC API JAR,而只有在运行的时候才需要 JDBC 驱动实现
testCompile:
测试期编译需要的附加依赖
testRuntime:
测试运行期需要
外部依赖包含 group,name 和 version 几个属性。根据选取仓库的不同,group 和 version 也可能是可选的。
当然,也有一种更加简洁的方式来声明外部依赖。采用:将三个属性拼接在一起即可。“group:name:version”
发布到 Maven私库:
//发布到私服
publishing {
publications {
maven(MavenPublication) {
groupId project.group
artifactId project.name
version project.version
//若是war包,就写components.web,若是jar包,就写components.java
from components.java
}
}
}
//私服配置
publishing {
repositories {
maven{
url ‘http://127.0.0.1:8081/repository/maven-snapshots/’
credentials {
username ‘admin’
password ‘admin123’
}
}
}
}