I am working on a Spring boot project where the deployment happens in Kubernetes. The gradle and docker configurations are such that it downloads all the dependencies into the docker image's libs directory during docker build and get the dependencies from libs during docker run.
This setting makes the docker run (which executes gradle build again) successful, even if I cut internet during this process.
build.gradle
plugins {
id 'java'
}
ext {
skipDownload = project.hasProperty('skipDownload') ? project.getProperty('skipDownload') as boolean : false
}
repositories {
mavenLocal()
if (skipDownload) {
flatDir {
dirs 'libs'
}
} else {
mavenCentral()
}
}
dependencies {
if (skipDownload) {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation fileTree(dir: 'testlibs', include: ['*.jar'])
} else {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.6.3'
}
}
task getDeps(type: Copy) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from configurations.compileClasspath into "libs/"
from configurations.runtimeClasspath into "libs/"
}
task getTestDeps(type: Copy) {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
from configurations.testCompileClasspath into "testlibs/"
from configurations.testRuntimeClasspath into "testlibs/"
}
Dockerfile
FROM gradle:7.3-jdk11
WORKDIR /app
COPY . .
RUN gradle --no-daemon test getDeps getTestDeps
CMD ["sh", "gradle bootRun"] // for this testing I will later change to gradle build during docker run command
Docker build
docker build -t service-test .
Docker run - AFTER CUTTING THE INTERNET
docker run --rm -it service-test gradle build -PskipDownload=true
These steps has been successful as expected. But when I add another plugin,as shown below, to support gradle booRun the step "Docker run - AFTER CUTTING THE INTERNET" is failing with the following error.
plugins {
id 'org.springframework.boot' version '2.6.3'
id 'java'
}
Plugin [id: 'org.springframework.boot', version: '2.6.3'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:2.6.3') Searched in the following repositories: Gradle Central Plugin Repository
Please direct me to fix this issue. I need to run the container offline.