//Gradle的配置文件本质是Groovy
group 'CicSearchJavaStu'
version '1.0-SNAPSHOT'
//sourceCompatibility = 1.5 //指定编译.java 文件的jdk版本
apply plugin: 'java' //引入Gradle的Java插件,这个插件提供所有构建和测试Java应用程序所需要的东西
apply plugin: 'scala'
def scalaVersion ='2.10.5'
apply plugin: 'maven-publish'
tasks.withType(JavaCompile){
options.encoding="UTF-8" //有时候,我们的代码使用UTF-8保存的,但是,进行gradle build的环境是gbk之类的,这时候会报错
}
//自定义项目,java插件为项目定义了许多默认配置,如果需要,这些配置都是由我们自己来定义的,并且增加一些属性到JAR包的manifest文件
jar{ //运行java程序时,为了告诉系统去哪里找外部的库文件,必须以Class-Path的形式把库的路径传递给jvm。基本的方式就是在
// Manifest文件中指定Class-Path.
manifest{
attributes 'Implementation-Title':'Gradle Quickstart', //属性
'Implementation-Version':version
}
}
//jar{
// manifest{ //incubating 版本,以后版本可能会改API
// attributes ("Main-Class":"com.KafkaWordCount",
// "Implementation-Title":"Gradle"
// )
// into('lib'){
// from configurations.runtime
// }
// }
//}
task sourceJar(type:Jar){ //表示创建的task是一个Jar Task。编译并打包成jar包
from sourceSets.main.allJava
}
publishing{
repositories{ //buildscript{}模块,声明使用Maven仓库,声明一个maven文件的依赖路径
maven{
url "http://192.168.1.100:8081/nexus/content/repositories/snapshots"
}
// credentials { //取消注释后编译会出错
// username 'admin'
// password 'admin123'
// }
}
publications {
maven(MavenPublication) {
from components.java
}
}
}
repositories {
//一个项目中可以使用多个仓库,Gradle会按顺序依次寻找,直到找到后停止寻找
// mavenLocal() //表示依赖从本地的Mvaven仓库获取的
maven { //通过URL或者本地文件地址,将maven仓库加入到我们的构建中
url System.getProperty("os.name").toLowerCase().contains("windows") ? "http://192.168.1.100:8081" : "https://repo1.maven.org/maven2/"
}
maven {
url "http://192.168.1.100:8081/nexus/content/repositories/snapshots"
}
maven {
url "http://192.168.1.100:8081/nexus/service/local/repositories/zb/content/"
}
flatDir { //系统会在lib目录中搜索依赖,可以多加入几个目录,dirs 'libA','libB'
dirs 'lib'
}
}
dependencies{
compile 'commons-httpclient:commons-httpclient:3.0.1'
//hbase
compile 'org.apache.hbase:hbase-client:1.0.0-cdh5.4.2'
//scala
compile 'org.scala-lang:scala-actors:' + scalaVersion
compile 'org.scala-lang:scala-reflect:' + scalaVersion
}
task copyToLib(type: Copy) {
into "$buildDir/libs/lib"
from configurations.runtime
}
jar { dependsOn copyToLib }
uploadArchives { //打包发布或发布,是查找外部依赖的反向操作,可以发布到仓库中,也可以发布到本地的“repos”目录中
repositories {
flatDir {
dirs 'repos'
}
}
}
latDir {
dirs 'repos'
}
}
}
转载请注明原文地址: https://ju.6miu.com/read-670771.html