Ani
Ani

Reputation: 1

Use dependencies downloaded during gradle clean during gradle bootRun

I am currently running a gradle project through Dockerfile. I require the build to be carried out on a development server which has internet connectivity and the docker image to be deployed on a production server which has no internet connectivity. For this purpose, I am trying to fetch all dependencies during gradle-clean. But when I run the docker image, it is again trying to download all the dependent jars from the repository. How can I make it point to the cache that is created during gradle-clean only. I am new to the Docker framework, any help is appreciated. Thank you.

The Dockerfile is as follows:

FROM openjdk:8

RUN mkdir -p /home/pma
WORKDIR /home/pma

VOLUME ["/home/pma"]
VOLUME ["/root/.gradle/caches/"]

#Setup gradle in the docker image and configure path variables
RUN \ 
    cd /usr/local && \
    curl -L https://services.gradle.org/distributions/gradle-4.2.1-bin.zip -o gradle-4.2.1-bin.zip && \
    unzip gradle-4.2.1-bin.zip && \
    rm gradle-4.2.1-bin.zip
ENV GRADLE_HOME=/usr/local/gradle-4.2.1
ENV PATH=$GRADLE_HOME/bin:$PATH

#Add the base code to the docker image
ADD . /home/pma/

#Here I am trying to download all dependencies which will be pushed to /root/.gradle/caches/
RUN ["gradle","--stacktrace","clean"]

#to be executed during the container creation phase
CMD ["gradle","--stacktrace","bootRun"]

Upvotes: 0

Views: 554

Answers (1)

Frito
Frito

Reputation: 446

I would prefer to build a complete docker image and bring it in production.

If you want to use cached dependencies only, use --offline when calling a gradle task.

Gradle is only resolving the dependencies of the configurations needed when executing a task, e.g. the compile dependencies won't be resolved without calling the compile task or another task based on the compile configuration and its dependencies.

You could write a custom task iterating through all configurations and resolving the dependencies.

Looks like somebody else had this problem before: Gradle Task to Resolve All Configured Dependencies

This is what he was doing some years ago (I didn't test it myself):

task resolveDependencies {
    doLast {
        project.rootProject.allprojects.each { subProject ->
            subProject.buildscript.configurations.each { configuration ->
                configuration.resolve()
            }
            subProject.configurations.each { configuration ->
                configuration.resolve()
            }
        }
    }
}

Upvotes: 1

Related Questions