Gradle管理的工程里,build.gradle文件对项目起着非常重要的作业,本人用scala写了一个demo工程,大致结构如下:
看一下我的build.gradle 文件
// 项目归属和版本号
group 'com.tencent.pcg'
version '1.0-SNAPSHOT'
// buildscript中的声明是gradle脚本自身需要使用的资源。
// 可以声明的资源包括依赖项、第三方插件、maven仓库地址等
buildscript {
repositories {
maven { url 'http://maven.oa.com/nexus/content/repositories/central'}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.4.RELEASE")
}
}
// 使用 java 插件
apply plugin: 'java'
// 使用 springboot 框架
apply plugin: 'org.springframework.boot'
// 使用 Scala 插件
apply plugin: 'scala'
// 打的 jar 包的名称和版本信息
jar {
baseName = 'data-qulity-guard'
version = '0.0.1'
}
// demo main程序入口
task run(type: JavaExec, dependsOn: classes) {
main = 'com.tencent.pcg.ReadApiDemo'
classpath = sourceSets.main.runtimeClasspath
}
sourceCompatibility = 1.8
// 指定本地仓库 / 远程仓库
repositories {
mavenCentral()
// 使用公司内部的远程仓库
maven { url 'http://maven.oa.com/nexus/content/repositories/central'}
maven { url 'http://maven.oa.com/nexus/content/repositories/mqq/'}
maven { url 'http://maven.oa.com/nexus/content/groups/public/'}
}
// 依赖配置,引入依赖的 kafka,scala
dependencies {
compile("org.springframework.boot:spring-boot-starter-web:1.5.4.RELEASE")
compile("org.springframework.boot:spring-boot-starter:1.5.4.RELEASE")
compile("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2")
compile("mysql:mysql-connector-java:5.1.21")
compile("org.scala-lang:scala-library:2.11.4")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile("org.apache.kafka:kafka_2.11:0.8.2.1")
compile("qq-central:msg_fetch_api_3.0:1.0.0-SNAPSHOT"){
exclude group: 'org.apache.kafka', module: 'kafka_2.10'
}
testCompile group: 'junit', name: 'junit', version: '4.12'
}
写好 build 文件后刷新拉取最新配置
更新完成后本地测试没问题,即可直接点击 assemble
打 jar包