gradle 是一個讓構建自動化的工具,相似於maven,ant的功能.
使用gradle能夠給java項目編譯,單元測試,打包,或者生成可執行的jar包等html
gradle依賴java環境,因此使用gradle前須要安裝jdk 或jrejava
gradle的構建依賴於task, task能夠指定與其餘task之間的依賴關係 好比,有兩個task,walk 和bike,若是指定walk依賴bike,那麼 執行walk前會先執行bike.mysql
task的來源有兩種:git
gradle <任務名>
web
./gradlew <任務名>
redis
compile project.fileTree(dir:'/Users/whuanghkl/code/mygit/myproject/target',include:['io0007-0.0.1.jar'])
compile project.fileTree(dir:'/Users/xx/Documents/mygit/demo/io0007/target',include:['*.jar']) compile project.fileTree(dir:'/Users/xx/Documents/mygit/demo/idea_plugin/intellij-aa-editor/lib',include:['*.jar'])
使用project 下面的dependencies
spring
see /Users/whuanghkl/.gradle/wrapper/dists/gradle-4.4-all/9br9xq1tocpiv8o6njlyu5op1/gradle-4.4/src/core-api/org/gradle/api/Project.javasql
void dependencies(Closure configureClosure);
dependencies 方法的參數是一個配置閉包,那麼這個閉包有哪些配置呢?
參考:https://docs.gradle.org/current/userguide/java_plugin.html#tab:configurations
https://docs.gradle.org/current/userguide/managing_dependency_configurations.htmlapache
參考 https://docs.gradle.org/current/userguide/userguide.htmljson
gradle中依賴的倉庫有多種:
參考:https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.RepositoryHandler.html
咱們能夠選擇 maven倉庫:
repositories { mavenCentral() }
那麼查詢依賴就和maven同樣了.
個人項目是spring boot,因此須要引入插件'org.springframework.boot'
id 'org.springframework.boot' version '2.0.4.RELEASE'
須要在build.gradle 文件中 指定可執行jar的main class :
jar { manifest { attributes 'Main-Class': 'com.kunlunsoft.Application' } }
執行任務bootJar 就能夠生成可執行的jar包
https://my.oschina.net/huangweiindex/blog/1844872
https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.dsl.DependencyHandler.html
https://docs.gradle.org/current/userguide/java_plugin.html#tab:configurations
plugins { id 'java' id 'base' // id 'application' id 'org.springframework.boot' version '2.0.3.RELEASE' } //mainClassName = "com.kunlunsoft.Application" group 'com.kunlunsoft' version '1.0.0-SNAPSHOT' sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() } jar { manifest { attributes 'Main-Class': 'com.kunlunsoft.Application' } } task walk(description:'walk') { doLast { println 'walk...' } } repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } } dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' testCompile("org.springframework.boot:spring-boot-starter-test") //數據源 compile 'org.springframework.boot:spring-boot-starter:1.5.14.RELEASE' compile 'org.springframework.boot:spring-boot-starter-web:1.5.14.RELEASE' compile 'org.springframework.boot:spring-boot-starter-data-redis:1.5.14.RELEASE' compile 'mysql:mysql-connector-java:5.1.38' compile project.fileTree(dir:'/Users/whuanghkl/code/myproject/target',include:['io0007-0.0.1-SNAPSHOT.jar']) compile 'com.google.guava:guava:23.0-rc1' compile 'org.apache.commons:commons-email:1.5' compile 'org.codehaus.jackson:jackson-mapper-lgpl:1.9.12' //redis // compile 'org.springframework.data:spring-data-redis:1.8.13.RELEASE' compile 'redis.clients:jedis:2.9.0' compile 'org.springframework.statemachine:spring-statemachine-core:1.2.0.RELEASE' compile 'com.alibaba:fastjson:1.2.47' //配置mybatis compile "org.mybatis.spring.boot:mybatis-spring-boot-starter:1.1.1" compile 'org.springframework.boot:spring-boot-gradle-plugin:1.5.14.RELEASE' // compile 'org.springframework:springloaded:1.5.14.RELEASE' }