What is the equivalent of `npm install` for `gradle`?

Viewed 1907

Is there an equivalent of npm install for Gradle?

I wanted to cache layers of my Gradle build. Normally if it was an npm project I would do this

FROM node
COPY package.json package-lock.json .
RUN npm install # at this point the dependencies are downloaded
COPY src/ src/
RUN npm run build

So I am trying to do it the same way but with Gradle

FROM gradle:jdk12 AS build
COPY *.gradle .
RUN ????
COPY src/ src/
RUN gradle build
1 Answers

So as I see you are insterested in caching gradle depenencies in you docker image. You can use gradle dependencies to list dependencies and as side effect dependenices will be downloaded (you have to have build.gradle file already copied to the image) :

RUN gradle dependencies

or with gradle wrapper :

RUN ./gradlew dependencies

Also to force refreshing dependencies you could use --refresh-dependencies :

RUN gradle dependencies --refresh-dependencies
Related