Gradle安装

1. 安装Gradle

CentOS下安装
官网下载安装Gradle步骤,下载安装包以后解压并配置环境变量(不罗嗦了)

Ubuntu下安装
sudo apt-get install -f gradle

测试Gradle是否安装成功
gradle -v

2. 使用Gradle编译

gradle build
gradle会根据build.gradle文件自动下载依赖包,并把源码编译成jar包。

当然也可以在build.gradle文件中修改依赖,
举个我在编译Myriad时出现的一个例子(Myriad就不做介绍了,后面会对Myriad做一个简单的介绍):
dependencies { compile project(':myriad-commons') compile "org.apache.hadoop:hadoop-common:${hadoopVer}" compile "org.apache.hadoop:hadoop-yarn-common:${hadoopVer}" compile "org.apache.hadoop:hadoop-yarn-server-resourcemanager:${hadoopVer}" compile "com.lmax:disruptor:3.3.0" compile "io.dropwizard.metrics:metrics-core:${metricsVer}" compile "io.dropwizard.metrics:metrics-annotation:${metricsVer}" compile "io.dropwizard.metrics:metrics-healthchecks:${metricsVer}" compile "org.hibernate:hibernate-validator:5.1.2.Final" compile "com.fasterxml.jackson.core:jackson-annotations:2.5.1 compile "com.fasterxml.jackson.core:jackson-databind:2.5.1 compile "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.5.1 compile "org.apache.curator:curator-framework:2.7.1" compile "org.apache.commons:commons-lang3:3.4" compile 'com.google.inject.extensions:guice-multibindings:3.0' testCompile "org.apache.hadoop:hadoop-yarn-server-resourcemanager:${hadoopVer}:tests" }
由于Myriad编译jackson的版本是2.5.1,编译完成后把jar包复制到YARN_HOME/lib/下,但是yarn自带的jacksoon包是2.2.3,这样就会发生版本冲突,所以在使用gradle进行编译的时候就要把版本号修改好。

    原文作者:扳掘de
    原文地址: https://www.jianshu.com/p/f528d137db67
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞