Skip to content

Minimal script for Kotlin only library that supports publishing on JCenter

Alex Shafir edited this page Dec 31, 2020 · 6 revisions

Root project script to publish Kotlin-only library, Gradle 6+ & latest components, multi-module setup.

In order to be publish-able on JCenter, you must add pom closure inside mavenJava closure!

You execute publishing with gradle bintrayUpload.

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.4.21"
    ext.latest_version = "1.0.0"
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:4.1.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Properties properties = new Properties()
properties.load(project.rootProject.file("local.properties").newDataInputStream())



subprojects{ // Specify dependencies in project build.gradle

    if(it.name == "app") return // Filter out projects you do not want to publish

    apply plugin: "com.jfrog.bintray"
    apply plugin: "maven-publish"
    apply plugin: "kotlin" // You must specify plugin here

    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8

    java {
        withSourcesJar()
        withJavadocJar()
    }

    publishing {
        publications {
            mavenJava(MavenPublication) {
                groupId "my.group.id"
                artifactId project.name
                version latest_version
                from components.java

                pom {
                    name = libraryName
                    description = libraryDescription
                    url = siteUrl

                    licenses {
                        license {
                            name = licenseName
                            url = licenseUrl
                        }
                    }
                    developers {
                        developer {
                            id = developerId
                            name = developerName
                            email = developerEmail
                        }
                    }
                    scm {
                        connection = gitUrl
                        developerConnection = gitUrl
                        url = siteUrl

                    }
                }
            }
        }
    }

    bintray {
        user = properties.getProperty("bintray.user")
        key = properties.getProperty("bintray.apikey")
        publications = ["mavenJava"]

        dryRun = false // Whether to run this as dry-run, without deploying
        publish = true // Whether version should be auto published after an upload
        override = true // Whether to override version artifacts already published
        pkg {
            repo = "MyRepo"
            name = "my.group.id.${project.name}"

            version {
                name = latest_version
            }

        }
    }

}
Clone this wiki locally