进入liferay v7.0,官方推荐使用Gradle进行依赖管理和发布,所以必须知道Gradle的用法,网上资料很多,不赘述
只写依赖管理的分类
一般用外部仓库依赖,也可以用本地文件依赖(依赖本地jar包),如:
本地文件依赖
dependencies {
//单文件依赖
compile files('libs/activiti-engine-5.21.0.jar')
//某文件夹的全部依赖
compile fileTree(dir: 'libs', include: '*.jar')
其中libs目录,与build.gradle目录在同一个文件夹下。
Gradle外部仓库依赖一般有两种写法:
- 写法1:compile
- 写法2:compile group XXX
实际上都是一样的。
比如activiti的依赖:
compile group: 'org.activiti', name: 'activiti-engine', version: '5.21.0'
如果熟悉Maven,会很熟悉,只是Maven用的是XML格式:
<!-- https://mvnrepository.com/artifact/org.activiti/activiti-engine -->
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>5.21.0</version>
</dependency>
一堆Gradle依赖写在一起:
compile group: 'joda-time', name: 'joda-time', version: '2.6'
compile group: 'org.activiti', name: 'activiti-bpmn-converter', version: '5.21.0'
compile group: 'org.activiti', name: 'activiti-process-validation', version: '5.21.0'
compile group: 'org.activiti', name: 'activiti-image-generator', version: '5.21.0'
compile group: 'org.apache.commons', name: 'commons-email', version: '1.4'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
compile group: 'org.mybatis', name: 'mybatis', version: '3.3.0'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.6'
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.6'
compile group: 'org.springframework', name: 'spring-beans', version: '4.1.5.RELEASE'
compile group: 'org.activiti', name: 'activiti-engine', version: '5.21.0'
Gradle仓库有4种使用方法,请按情况转换
1、使用maven*仓库:
repositories {
mavenCentral()
} 2、使用私有aven远程仓库:
repositories {
maven {
url "http://repo.Yourcompany.com/public"
}
} 3、远程Ivy仓库:
repositories {
ivy {
url "http://repo.Yourcompany.com/public"
}
} 4、本地Ivy仓库:
repositories {
ivy {
url "../local-repo"
}
}
可以使用多个仓库,Gradle会按顺序依次寻找,找到后会停止寻找,一般把最快的URL放最前边,最后放本地Ivy仓库。
常用的仓库:
http://central.maven.org/maven2/
http://repo1.maven.org/maven2
http://repo2.maven.org/maven2/
发布你自己的JAR包
发布artifacts到一个Maven私有仓库:
apply plugin: 'maven' uploadArchives {
repositories {
mavenDeployer {
repository(url: "file://localhost/tmp/myRepo/")
}
}
}
发布到远程公共仓库:
uploadArchives {
repositories {
ivy {
credentials {
username "username"
password "pw"
}
url "http://repo.mycompany.com"
}
}
}