Skip to content

Instantly share code, notes, and snippets.

@ankitthakur
Created August 28, 2018 04:58
Show Gist options
  • Save ankitthakur/af2e8801e071213a698a625370038db0 to your computer and use it in GitHub Desktop.
Save ankitthakur/af2e8801e071213a698a625370038db0 to your computer and use it in GitHub Desktop.
gradle kotlin docker task
buildscript {
ext {
kotlinVersion = '1.2.51'
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
// add docker dependency
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.0.3.RELEASE")
// using Gradle you need to add a new docker plugin like this:
classpath('se.transmode.gradle:gradle-docker:1.2')
}
}
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'eclipse-wtp'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
// apply this docker plugin
apply plugin: 'docker'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
compileKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs = ["-Xjsr305=strict"]
jvmTarget = "1.8"
}
}
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-web')
compile('com.fasterxml.jackson.module:jackson-module-kotlin')
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
compile("org.jetbrains.kotlin:kotlin-reflect")
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
// write this docker build task, this will run just after "./gradlew build" command
task buildDocker(type: Docker, dependsOn: build) {
push = true
applicationName = bootJar.baseName
dockerfile = file('Dockerfile')
doFirst {
copy {
from jar
into stageDir
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment