第一个gradle工程

1. 下载gradle,并配置

2. 配置idea的gradle(不支持,可以下插件)

3. 创建gradle项目

4 配置依赖

 1 plugins {
 2     id 'java'
 3 }
 4 
 5 group 'com.xf'
 6 version '1.0'
 7 
 8 //jdk encode
 9 sourceCompatibility = 1.8
10 targetCompatibility = 1.8
11 compileJava.options.encoding = 'UTF-8'
12 compileJava.options.encoding = 'UTF-8'
13 
14 //仓库配置
15 repositories {
16     mavenLocal()        //使用本地仓库
17     maven { name "Alibaba"; url "https://maven.aliyun.com/repository/public" }
18     mavenCentral()      //使用maven中心仓库
19 }
20 
21 //版本控制
22 project.ext {
23     hadoopVersion = '2.6.5'
24     sparkVersion = '2.4.0'
25     scalaVersion = '2.11.8'
26     slf4jVersion = '1.7.7'
27     log4jVersion = '1.2.17'
28     hbaseVersion = '2.2.0'
29     esVersion = '7.3.1'
30     junitVersion = '4.12'
31 }
32 //
33 dependencies {
34     compile group: 'org.apache.spark', name: 'spark-core_2.11', version: sparkVersion
35     compile(
36             'org.apache.hadoop:hadoop-client:' + hadoopVersion,
37             'org.apache.spark:spark-sql_2.11:' + sparkVersion,
38             'org.scala-lang:scala-library:' + scalaVersion,
39             'org.elasticsearch.client:elasticsearch-rest-high-level-client:' + esVersion,
40             'org.apache.hbase:hbase-client:' + hbaseVersion
41     )
42     runtime(
43             'org.slf4j:slf4j-log4j12:' + slf4jVersion,
44             'log4j:log4j:' + log4jVersion
45     )
46     testCompile group: 'junit', name: 'junit', version: junitVersion
47 }
View Code

 

5 并测试运行

第一个gradle工程_第1张图片

 

你可能感兴趣的:(第一个gradle工程)