声明依赖
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
外部依赖
dependencies {
compile group: 'org.hibernate', name: 'hibernate-core', version: '3.6.7.Final'
}
这样的依赖还可以写为简短的方式
dependencies {
compile 'org.hibernate:hibernate-core:3.6.7.Final'
}
库 Repositories
使用repositories 指定上面的依赖从哪个库中获取
从maven中央仓库中获取
repositories {
mavenCentral()
}
或者从Bintray的JCenter仓库中获取
repositories {
jcenter()
}
或者是其他的远端的maven仓库
repositories {
maven {
url "http://repo.mycompany.com/maven2"
}
}
或者是远端的其lvy文件夹
repositories {
ivy {
url "http://repo.mycompany.com/repo"
}
}
或者是本地的lvy文件夹
repositories {
ivy {
// URL can refer to a local directory
url "../local-repo"
}
}
发布文件包
发布到lvy 仓库
uploadArchives {
repositories {
ivy {
credentials {
username "username"
password "pw"
}
url "http://repo.mycompany.com"
}
}
}
发布到maven仓库
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://localhost/tmp/myRepo/")
}
}
}
在build中依赖task
task run {
dependsOn gradle.includedBuild('my-app').task(':run')
}
task publishDeps {
dependsOn gradle.includedBuilds*.task(':uploadArchives')
}
网友评论