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-common:2.7.1",
"org.apache.hadoop:hadoop-hdfs:2.7.1",
"org.apache.hadoop:hadoop-mapreduce-client-core:2.7.1",
"org.apache.hadoop:hadoop-mapreduce-client-jobclient:2.7.1",
"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'}
}
//gradle copyJars
task copyJars(type: Copy) {
from configurations.runtime
into 'lib' // 目标位置
}
/*dependencies {
//加载本地依赖
compile fileTree(dir: 'E:/test/libs', include: '*.jar')
}*/
/*
//jar上传路径
uploadArchives{
}*/
//gradle build fatJar
//\build\libs
gradle 文件
最新推荐文章于 2024-08-30 18:40:43 发布