gradle相关配置

1、包下载文件
C:\Users\wangqiao\.gradle\caches\modules-2\files-2.1

2、gradle 配置
apply plugin: 'java'
apply plugin: 'maven'

group = 'com.laifeng'
version = '0.0.1-SNAPSHOT'

description = """ddshow-hadoop"""

sourceCompatibility = 1.6
targetCompatibility = 1.6

repositories {
        
     maven { url "http://repos.1verge.net/nexus/content/groups/public" }
     maven { url "http://repos.1verge.net/nexus/content/groups/public-snapshots" }
     maven { url "http://repo.data.1verge.net/nexus/content/groups/public/" }
     maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
    compileJava {
        options.encoding="UTF-8"
    }

    compile group: 'com.alibaba', name: 'fastjson', version:'1.1.31'
    compile(group: 'mysql', name: 'mysql-connector-java', version:'5.1.20') {
       
    }
    compile(group: 'org.apache.hadoop', name: 'hadoop-core', version:'1.0.3') {
      
    }
    compile(group: 'org.apache.hive', name: 'hive-exec', version:'0.12.0') {
      
    }
}


参考
http://www.jiechic.com/archives/the-idea-and-gradle-use-summary

中文帮助手册
http://pkaq.github.io/gradledoc/docs/userguide/userguide.html

-------------------------------------
1、解决中文
compileJava {
options.encoding="UTF-8"
}
2、自动生成
gradle init --type pom

gradle 例子
https://github.com/pkainulainen/gradle-examples

-----------------------------------------------

gradle hadoop 配置例子
1、配置文件

apply plugin: 'java' //指定项目为java项目,项目编译(在项目提示符下执行:gradle build)时生成项目的jar包
apply plugin: 'maven'//使用maven做为jar包的信赖管理,通过mave仓库下载项目所需的信赖包
apply plugin: 'idea'//启用idea插件

configurations{
    provided
}

sourceCompatibility = 1.6

targetCompatibility = 1.6

version = '0.0.1-SNAPSHOT' //版本
group='com.laifeng'          //组

//配置文件编码为UTF-8
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

//maven仓库配置
repositories {
    mavenLocal()
    maven { url "http://repos.1verge.net/nexus/content/groups/public" }
    maven { url "http://repo.data.1verge.net/nexus/content/groups/public/" }
    mavenCentral()
}


dependencies {
    //测试级别的依赖
    //testCompile group: 'junit', name: 'junit', version: '4.11'

    //compile为编译级别依赖
    compile(
            "mysql:mysql-connector-java:5.1.20",
            "org.apache.hadoop:hadoop-core:1.0.3",
            "org.apache.hive:hive-exec:0.12.0",
            "com.alibaba:fastjson:1.1.31"
    )
    //打包时依赖
    provided('com.alibaba:fastjson:1.1.31')
}

//自定义任务  将打包时依赖的包打入jar中
task fatJar(type: Jar) {
    //包名
    baseName = 'ddshow-hadoop-gradle-jar-with-dependencies'
    from {
        configurations.compile.collect {
            it.isDirectory() ? it : zipTree(it)
        }
        configurations.provided.collect {
            it.isDirectory() ? it : zipTree(it)
        }
    }
    from{'build/classes/main'}
}

/*dependencies {
    //加载本地依赖
    compile fileTree(dir: 'E:/test/libs', include: '*.jar')
}*/

/*
//jar上传路径
uploadArchives{

}*/



2、/d/IDEA/idea_project_new/ddshow-data/ddshow-hadoop-gradle 

rootProject.name = 'ddshow-hadoop-gradle'

gradle build
D:\IDEA\idea_project_new\ddshow-data\ddshow-hadoop-gradle\build\libs\ddshow-hadoop-gradle-0.0.1-SNAPSHOT.jar

gradle fatJar
ddshow-hadoop-gradle-jar-with-dependencies-0.0.1-SNAPSHOT.jar

gradle build fatJar

猜你喜欢

转载自wangqiaowqo.iteye.com/blog/2217875