Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle alternate to mvn install

Tags:

maven-2

gradle

People also ask

What is equivalent of MVN install in Gradle?

gradle install publishes into the local Maven repo, and mavenLocal() makes sure to look there for dependencies.

Can I use Gradle instead of Maven?

In the end, what you choose will depend primarily on what you need. Gradle is more powerful. However, there are times that you really do not need most of the features and functionalities it offers. Maven might be best for small projects, while Gradle is best for bigger projects.

How do I change from Maven to Gradle?

To convert Maven to Gradle, the only step is to run gradle init in the directory containing the POM. This will convert the Maven build to a Gradle build, generating a settings. gradle file and one or more build.

Why we use Gradle instead of Maven?

Gradle allows custom dependency scopes, which provides better-modeled and faster builds. Maven dependency conflict resolution works with a shortest path, which is impacted by declaration ordering. Gradle does full conflict resolution, selecting the highest version of a dependency found in the graph.


sdk/build.gradle:

apply plugin: "maven"

group = "foo"
version = "1.0"

example/build.gradle:

repositories {
    mavenLocal()
}

dependencies {
    compile "foo:sdk:1.0"
}

$sdk> gradle install

$example> gradle build

You may be looking for:

gradle publishToMavenLocal

Available with:

apply plugin: 'maven-publish'

See: Maven Publish Plugin


Check out Gradle's documentation on multi-project builds.

Here's an example, with some extra dependencies. Just call gradle install in the root folder, and all will be built and put to your local repo.

Folder structure:

root
+--> build.gradle
+--> settings.gradle
+--> sdk
|    +--> build.gradle
+--> example
     +--> build.gradle

root/build.gradle:

allprojects {
  apply plugin: 'java'
  apply plugin: 'maven'

  group = 'myGroup'
  version = '0.1-SNAPSHOT'
}

root/settings.gradle:

include 'sdk'
include 'example'

root/sdk/build.gradle:

dependencies {
  // just an example external dep.
  compile group:'commons-lang', name:'commons-lang', version:'2.3'
}

root/example/build.gradle:

dependencies {
  compile project(':sdk')
  compile group:'log4j', name:'log4j', version:'1.2.16'
}

You need to publish your own library to your local repository. You can do that in the following way:

  1. Add maven-publish plugin:

    plugins {
        // your other plugins come here...
        id 'maven-publish'
    }
    
  2. Add the publishing section to your build file:

    publishing {
        publications {
            myCoolLibrary(MavenPublication) {
                from components.java
            }
        }
    }
    
  3. Run gradle build publishToMavenLocal

    Find more details in the documentation.