Created
December 18, 2018 23:16
gradle + spring boot + docker
This file contains hidden or 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
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 | |
} |
This file contains hidden or 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: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"] |
This file contains hidden or 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 = 'main-service' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment