Gradle alternate to mvn install

Maven 2Gradle

Maven 2 Problem Overview


I have 2 different project build on mvn. I am trying to replace to Gradle.

Project 1 is an SDK, and project 2 is using that sdk (example).

In the time of maven it creates artifact using mvn install which adds the whole project into local repository.

I like to work in gradle like that. I like project 1 build.gradle need to post it as a gradle local repository and then example project need to use it.

In maven we do mvn install which adds a project artifact into .m2 folder but how to do in gradle so what i can add a project artefact's into the local repository.

Any way that I can do so?

Maven 2 Solutions


Solution 1 - Maven 2

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

   

Solution 2 - Maven 2

You may be looking for:

gradle publishToMavenLocal

Available with:

apply plugin: 'maven-publish'

See: Maven Publish Plugin

Solution 3 - Maven 2

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'
}

Solution 4 - Maven 2

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRajmahendraView Question on Stackoverflow
Solution 1 - Maven 2Peter NiederwieserView Answer on Stackoverflow
Solution 2 - Maven 2Miguel ReyesView Answer on Stackoverflow
Solution 3 - Maven 2csaba.sulyokView Answer on Stackoverflow
Solution 4 - Maven 2Sasha ShpotaView Answer on Stackoverflow