Skip to content

Instantly share code, notes, and snippets.

@larrybolt
Created December 18, 2018 23:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larrybolt/2750cb0d5ee3bc20353d023cd5dab27f to your computer and use it in GitHub Desktop.
Save larrybolt/2750cb0d5ee3bc20353d023cd5dab27f to your computer and use it in GitHub Desktop.
gradle + spring boot + docker
buildscript {
ext {
springBootVersion = '2.1.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
//apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
springBoot {
mainClassName = 'com.example.mainservice.MainApplication'
}
//springBoot {
// mainClassName = "com.example.mainservice.MainApplication"
//}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
runtimeOnly('org.springframework.boot:spring-boot-devtools')
compileOnly('org.projectlombok:lombok')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
task resolveDependencies {
doLast {
project.rootProject.allprojects.each { subProject ->
subProject.buildscript.configurations.each { configuration ->
resolveConfiguration(configuration)
}
subProject.configurations.each { configuration ->
resolveConfiguration(configuration)
}
}
}
}
void resolveConfiguration(configuration) {
if (isResolveableConfiguration(configuration)) {
configuration.resolve()
}
}
boolean isResolveableConfiguration(configuration) {
def nonResolveableConfigurations = ['apiElements', 'implementation',
'runtimeElements', 'runtimeOnly',
'testImplementation', 'testRuntimeOnly',
'generatedImplementation', 'generatedRuntimeOnly']
if (nonResolveableConfigurations.contains(configuration.getName())) {
return false
}
return true
}
FROM gradle:5.0-alpine AS build
ENV APP_HOME=/app
USER root
RUN mkdir -p $APP_HOME/
WORKDIR $APP_HOME
# download dependencies
COPY build.gradle settings.gradle ./
RUN gradle resolveDependencies
# compile
COPY src ./src
RUN gradle build
# Based on https://github.com/GoogleContainerTools/distroless/blob/master/examples/java/Dockerfile
FROM gcr.io/distroless/java
USER root
COPY --from=build /app/build/libs/main-service-0.0.1-SNAPSHOT.war /
WORKDIR /
CMD ["main-service-0.0.1-SNAPSHOT.war"]
rootProject.name = 'main-service'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment