Last active
February 5, 2020 13:00
-
-
Save adamatti/eea5df43e09a6056d3fac52843d2befe to your computer and use it in GitHub Desktop.
Docker/Gradle/Kotlin/SpringBoot problem: doesn't cache gradle plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Created with https://start.spring.io, select gradle / kotlin | |
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | |
/* Try 3: use old gradle structure | |
buildscript { | |
repositories { | |
jcenter() | |
maven { | |
url = uri("https://plugins.gradle.org/m2/") | |
} | |
} | |
dependencies { | |
classpath ("org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE") | |
classpath ("io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE") | |
classpath ("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61") | |
classpath ("org.jetbrains.kotlin:kotlin-allopen:1.3.61") | |
} | |
} | |
apply (plugin = "kotlin") | |
apply (plugin = "kotlin-spring") | |
apply(plugin = "org.springframework.boot") // https://plugins.gradle.org/plugin/org.springframework.boot | |
apply(plugin = "io.spring.dependency-management") // https://plugins.gradle.org/plugin/io.spring.dependency-management | |
//apply(plugin = "org.jetbrains.kotlin.jvm") // https://plugins.gradle.org/plugin/org.jetbrains.kotlin.jvm | |
//apply(plugin = "org.jetbrains.kotlin.plugin.spring") // https://plugins.gradle.org/plugin/org.jetbrains.kotlin.plugin.spring | |
*/ | |
plugins { | |
id("org.springframework.boot") version "2.2.4.RELEASE" | |
id("io.spring.dependency-management") version "1.0.9.RELEASE" | |
kotlin("jvm") version "1.3.61" | |
kotlin("plugin.spring") version "1.3.61" | |
} | |
group = "adamatti" | |
version = "0.0.1-SNAPSHOT" | |
java.sourceCompatibility = JavaVersion.VERSION_1_8 | |
repositories { | |
mavenCentral() | |
} | |
dependencies { | |
implementation("org.springframework.boot:spring-boot-starter") | |
implementation("org.jetbrains.kotlin:kotlin-reflect") | |
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | |
testImplementation("org.springframework.boot:spring-boot-starter-test") { | |
exclude(group = "org.junit.vintage", module = "junit-vintage-engine") | |
} | |
} | |
tasks.withType<Test> { | |
useJUnitPlatform() | |
} | |
tasks.withType<KotlinCompile> { | |
kotlinOptions { | |
freeCompilerArgs = listOf("-Xjsr305=strict") | |
jvmTarget = "1.8" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM gradle:6.1.1-jdk8 as builder | |
USER root | |
################################################################################ Try 1: have kotlin. Didn't work | |
#ENV KOTLIN_VERSION=1.3.61 \ | |
# KOTLIN_HOME=/usr/local/kotlin | |
#RUN cd /tmp && \ | |
# wget -k "https://github.com/JetBrains/kotlin/releases/download/v${KOTLIN_VERSION}/kotlin-compiler-${KOTLIN_VERSION}.zip" && \ | |
# unzip "kotlin-compiler-${KOTLIN_VERSION}.zip" && \ | |
# mkdir -p "${KOTLIN_HOME}" && \ | |
# mv "/tmp/kotlinc/bin" "/tmp/kotlinc/lib" "${KOTLIN_HOME}" && \ | |
# rm ${KOTLIN_HOME}/bin/*.bat && \ | |
# chmod +x ${KOTLIN_HOME}/bin/* && \ | |
# ln -s "${KOTLIN_HOME}/bin/"* "/usr/bin/" && \ | |
# rm -rf /tmp/* /var/cache/apk/* | |
################################################################################ | |
RUN mkdir /app | |
WORKDIR /app | |
################################################################################ Try 2: persist gradle/kotlin temp files. Didn't work | |
#RUN mkdir /gradle-tmp | |
#ENV JAVA_OPTS=-Djava.io.tmpdir=/gradle-tmp | |
################################################################################ | |
COPY build.gradle.kts /app | |
COPY settings.gradle.kts /app | |
RUN gradle dependencies --build-cache --no-daemon | |
COPY src /app/src | |
RUN gradle build --no-daemon -x test | |
# Goal: use '--offline'. Doesn't work, gradle still try download plugins | |
RUN gradle build --no-daemon --offline -x test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/main/kotlin | |
fun main(args: Array<String>){ | |
println("Hello world") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rootProject.name = "sample" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment