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
If it is specified in the configuration, it is able to download and manage Node. js distributions, unpack them into your local . gradle directory and use them from there. It also automatically installs npm when installing Node.
Gradle and npm are primarily classified as "Java Build" and "Front End Package Manager" tools respectively. "Flexibility" is the primary reason why developers consider Gradle over the competitors, whereas "Best package management system for javascript" was stated as the key factor in picking npm.
The npm install installs all modules that are listed on package. json file and their dependencies. npm update updates all packages in the node_modules directory and their dependencies.
npm install installs dependencies into the node_modules/ directory, for the node project you're working on. You can call install on another node. js project (module), to install it as a dependency for your project. npm run build does nothing unless you specify what "build" does in your package.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With