Sources: https://gradle.org/, spring guides, plugin:org.springframework.boot
Gradle is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven of declaring the project configuration.
what is basic things we need to do to setup a project.
Add a build.gradle file:
------------------------------------------------------------
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath('org.springframework.boot:spring-boot-gradle-plugin:1.4.0.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: 'application'
apply plugin: 'eclipse'
sourceCompatibility = 1.7
targetCompatibility = 1.7
jar {
baseName = 'jedis-impl'
version = '0.1.0'
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.springframework.boot:spring-boot-starter',
'redis.clients:jedis:1.5.0'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
test {
systemProperties 'property': 'value'
}
task wrapper (type: Wrapper) {
gradleVersion='2.0'
}
------------------------------------------------------------
gradle wrapper #Generates a gradle configuration within project, so that project can be built or executed even if gradle is installed on any system or not.
./gradlew bootrun #It simply downloads all required dependencies and build project. finally it runs project.
##Useful Plugins .
1. ssh - for transfer built deployable to specific node.
classpath 'org.hidetake:gradle-ssh-plugin:0.3.10' //Add this in buildscript dependencies.
apply plugin: 'ssh'
2. shadow - for packaging jars.
repository in build script should include below URL:
maven{
url "https://plugins.gradle.org/m2/"
}
dependency in build script should contian:
classpath 'com.github.jengelman.gradle.plugins:shadow:1.0.2' //Add this in buildscript dependencies.
add plugin
apply plugin: 'com.github.johnrengelman.shadow'
##Kill all gradle instances. (usefull in killing java process running in background via gradle process on which no handle is present.)
gradle --stop
##Create project with gradle init plugin
gradle init --type java-application
##Add local jar file as dependency..
dependencies{
compile files('local-libs/common-1.0.jar','OTHER_JAR_IF_ANY')
}
##Exclude sub dependency where conflicts are detected.
compile('<SOME_DEPENDENCY>'){
exclude group:'<GROUP_NAME>'
}
apply plugin adds tasks and configuration from mentioned plugin name.
Plugins defines source of plugin to be applied. It is substitute of buildscript block used in older version of gradle script.