从MAVEN迁移到gradle

从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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值