Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

gradle

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
like image 744
Archimedes Trajano Avatar asked Oct 28 '19 14:10

Archimedes Trajano


People also ask

Can you install gradle with npm?

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.

Is gradle same as npm?

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.

What npm install install?

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.

Can I run npm build without npm install?

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.


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
like image 132
Michał Krzywański Avatar answered Oct 22 '22 02:10

Michał Krzywański