Gradle – publish artifacts to Maven local repository

Short tutorial about how to create a Gradle task publishing (installing) artifacts into Maven local repository.

First of all, we need to import a ‘maven-publish’ plugin:

plugins {
    id 'maven-publish'
}

Next, we have to have a mavenLocal() as the first registry in repositories:

repositories {
        mavenLocal()
        //other repositories
    }

The plugin uses first defined repository as the target.

The minimal configuration of the task should look like this:

publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java
        }
    }
}

By running task publishToMavenLocal, the plugin will install compiled jar into Maven local repository along with the pom file generated based on the project properties (group, version, etc).

For plugin reference and custom configuration see  https://docs.gradle.org/current/userguide/publishing_maven.html