从MAVEN迁移到GRADLE多少会有不习惯,这里总结几点MAVEN常用的操作在GRADLE中的对应操作(eclipse环境下)
1.GRADLE插件的安装:使用spring的GRADLE ide
WINDOW-->PREFRENCE -->设置GRADLE HOME (GRADLE
插件目录),GRADLE user home(jar仓库的目录)
2.JDK版本的设置需要手工调整,ECLIPSE没有提供像MAVEN那样好的支持,BUILD PATH的设置也是类似的;
build.gradle设置:
sourceCompatibility = 1.7
targetCompatibility = 1.7
3.优先使用已有的本地MAVEN仓库,此处
需要在USER_HOME/.m2/settings.xml中设置local位置 ;
优先级如下:本地MAVEN仓库 > 本地GRADLE仓库-->服务器上的仓库
repositories {
// USER_HOME/.m2/settings.xml中设置local位置
mavenLocal()
mavenCentral()
}
4.install和deploy到maven仓库;
build.gradle添加maven相关的支持,gradle没有artifactId 概念,需要自定义;
apply plugin: 'maven'
group 'my-company'
version '1.0-SNAPSHOT'
def artifactId = "my-artifact"
def releaseTime() {
return new Date().format("yyyy-MM-dd HH:mm:ss")
}
install {
repositories.mavenInstaller {
pom.version = "$project.version"
pom.artifactId = "$artifactId"
pom.groupId = "$project.group"
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "
http://172.16.52.5:8081/nexus/content/repositories/snapshots/") {
authentication(userName: "deployment", password: "maven")
}
pom.version = "$project.version"
pom.artifactId = "$artifactId"
pom.groupId = "$project.group"
}
}
}
5.总结GRADLE比起maven更灵活,可编程可操控性更强;但由于灵活性也导致无法标准化,工具层面都没有很好的支持;eclipse默认支持maven,缺没有一款强大的gradle插件,已有的gradle插件和maven插件比起来也是非常简陋的。
==========================================================
build.gradle源文件:------------------------------------->
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'
group 'my-company'
version '1.0-SNAPSHOT'
def artifactId = "my-artifact"
def releaseTime() {
return new Date().format("yyyy-MM-dd HH:mm:ss")
}
sourceCompatibility = 1.7
targetCompatibility = 1.7
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart',
'Implementation-Version': version,
'Archive-Time':releaseTime()
}
}
repositories {
// USER_HOME/.m2/settings.xml中设置local位置
mavenLocal()
mavenCentral()
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
test {
systemProperties 'property': 'value'
}
//uploadArchives {
// repositories {
// flatDir {
// dirs 'repos'
// }
// }
//}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
install {
repositories.mavenInstaller {
pom.version = "$project.version"
pom.artifactId = "$artifactId"
pom.groupId = "$project.group"
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: "
http://172.16.52.5:8081/nexus/content/repositories/snapshots/") {
authentication(userName: "deployment", password: "maven")
}
pom.version = "$project.version"
pom.artifactId = "$artifactId"
pom.groupId = "$project.group"
}
}
}
J2EE系统架构交流群: 203431569