Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use gradle to upload jar to local Maven repository

This question has been asked several times, but somehow I don't get this to work. Gradle is a great tool, but its documentation is anything but great. No examples make it almost impossible to understand for someone who doesn't use it on a daily basis.

I am using Android Studio and I want to upload my module output jar to my local Maven repository.

apply plugin: 'java'

dependencies {
    compile 'com.google.http-client:google-http-client-android:1.18.0-rc'
}


apply plugin: 'maven'
configure(install.repositories.mavenInstaller) {
    pom.project {
        groupId 'com.example'
        artifactId 'example'
        packaging 'jar'
    }
}

When I start a build in Android Studio, I can see on the Gradle tab that

:install

is invoked. I also get a new jar in my build folder, but that jar is not uploaded to Maven. [The Maven repo exists and the Google appengine gradle plugin uploads its jar from another module of the same project just fine.]

What am I missing?

like image 275
Oliver Hausler Avatar asked Aug 10 '14 22:08

Oliver Hausler


People also ask

Does Gradle use Maven local repository?

Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven repository with one project and consume the artifacts by Gradle in another project.

Can I use Gradle dependency in Maven?

Gradle understands different repository types, such as Maven and Ivy, and supports various ways of accessing the repository via HTTP or other protocols. You can also have repositories on the local file system. This works for both Maven and Ivy repositories.

How do I migrate from Gradle to Maven?

To convert Gradle to Maven, first, Maven plugin need to be added in the build. gradle file. Then, simply run Gradle install in the directory. Lastly, simply run gradle install and the directory containing build.


1 Answers

I suspect the problem is that you are only editing the POM (via pom.project), instead of configuring the actual Maven coordinates used for installation. Try the following instead:

// best way to set group ID
group = 'com.example'

install {
    repositories.mavenInstaller {
        // only necessary if artifact ID diverges from project name
        // the latter defaults to project directory name and can be
        // configured in settings.gradle
        pom.artifactId = 'myName' 
        // shouldn't be needed as this is the default anyway
        pom.packaging = 'jar'
    }
}

PS: The samples directory in the full Gradle distribution contains many example builds, also for the maven plugin.

like image 56
Peter Niederwieser Avatar answered Oct 01 '22 03:10

Peter Niederwieser