33

I am new in gradle hence I have some questions about gradle. Before gradle I worked with maven and in maven there are some commands such as

  • mvn update
  • mvn clean install

With mvn update we download the dependency packages from internet and the other packages from the different projects.

With mvn install we create the jar, war, ear or ejb so what are the equivalents for maven command in gradle?

  • mvn update ~= gradle ...

    and

  • mvn clean install ~= gradle clean ...

Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
suatCoskun
  • 812
  • 2
  • 10
  • 14
  • I don't know much about Maven, but Gradle specifically provides `jar` and `war` tasks if the corresponding plugins (`java` and `war` respectively) are declared in `build.gradle` – rrobby86 Jun 26 '17 at 08:44
  • Have a look at this guide: https://guides.gradle.org/migrating-from-maven/ – larsgrefer Jun 26 '17 at 09:36

4 Answers4

50

Gradle will automatically fetch all required dependencies for you.

Long story short:

mvn update        ~= ./gradlew build --refresh-dependencies
mvn clean install ~= ./gradlew clean build

TL;DR

To force Gradle to redownload dependencies you can execute (How can I force gradle to redownload dependencies?):

./gradlew build --refresh-dependencies

To assemble you project without executing tests (Gradle build without tests):

./gradlew assemble

To completely build you project with test execution:

./gradlew build

You can skip certain tasks by providing -x argument:

./gradlew build -x test
Andrii Abramov
  • 10,019
  • 9
  • 74
  • 96
  • 5
    The counterpart for maven's _install_ phase should be gradle's _install_ task (provided by the `maven` plugin) or the _publishToMavenLocal_ task (provided by the `maven-publish` plugin) – larsgrefer Jun 26 '17 at 09:32
12

The equivalent to

mvn clean install 

is

gradle install

what is provided by the maven plug-in of Gradle. Just add the following line to your build.gradle file:

apply plugin: 'maven'
deamon
  • 89,107
  • 111
  • 320
  • 448
1

This works for me.

./gradlew publishToMavenLocal
vintuwei
  • 788
  • 8
  • 7
0

Here is the command:

./gradlew build
Aivean
  • 10,692
  • 25
  • 39
  • 1
    This has already been mentioned in [this answer](https://stackoverflow.com/a/44755949/2227743). *When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers.* – Eric Aya Nov 14 '21 at 10:09