aboutsummaryrefslogtreecommitdiffstats
path: root/gradle/publish.gradle
blob: 3a0a4224ab9259a8f8cb23719cd6feea0f0111aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
 */

import org.gradle.util.VersionNumber

// Configures publishing of Maven artifacts to Maven Central

apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'signing'

// ------------- tasks

def isMultiplatform = project.name == "kotlinx-coroutines-core"
def isBom = project.name == "kotlinx-coroutines-bom"

if (!isBom) {
    apply plugin: "com.github.johnrengelman.shadow"

    // empty xxx-javadoc.jar
    task javadocJar(type: Jar) {
        archiveClassifier = 'javadoc'
    }
}

if (!isMultiplatform && !isBom) {
    // Regular java modules need 'java-library' plugin for proper publication
    apply plugin: 'java-library'

    // MPP projects pack their sources automatically, java libraries need to explicitly pack them
    task sourcesJar(type: Jar) {
        archiveClassifier = 'sources'
        from sourceSets.main.allSource
    }
}

publishing {
    repositories {
        PublishingKt.configureMavenPublication(delegate, project)
    }

    if (!isMultiplatform && !isBom) {
        // Configure java publications for regular non-MPP modules
        publications {
            maven(MavenPublication) {
                if (project.name == "kotlinx-coroutines-debug") {
                    project.shadow.component(it)
                } else {
                    from components.java
                }
                artifact sourcesJar
            }
        }
    }

    publications.all {
        PublishingKt.configureMavenCentralMetadata(pom, project)
        PublishingKt.signPublicationIfKeyPresent(project, it)
        // add empty javadocs
        if (!isBom && it.name != "kotlinMultiplatform") {
            it.artifact(javadocJar)
        }

        def type = it.name
        switch (type) {
            case 'kotlinMultiplatform':
                // With Kotlin 1.4 & HMPP, the root module should have no suffix in the ID, but for compatibility with
                // the consumers who can't read Gradle module metadata, we publish the JVM artifacts in it, too
                it.artifactId =  project.name
                apply from: "$rootDir/gradle/publish-mpp-root-module-in-platform.gradle"
                publishPlatformArtifactsInRootModule(publications["jvm"])
                break
            case 'metadata':
            case 'jvm':
            case 'js':
            case 'native':
                it.artifactId = "$project.name-$type"
                break
        }
    }
}

tasks.matching { it.name == "generatePomFileForKotlinMultiplatformPublication"}.configureEach {
    dependsOn(tasks["generatePomFileForJvmPublication"])
}

// Compatibility with old TeamCity configurations that perform :kotlinx-coroutines-core:bintrayUpload
task bintrayUpload(dependsOn: publish)