xref: /aosp_15_r20/external/kotlinx.atomicfu/gradle/publishing.gradle (revision 68017707106cb9da9fed635c150bc497c09c160f)
1/*
2 * Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3 */
4
5// Configures publishing of Maven artifacts to Bintray
6
7apply plugin: 'maven-publish'
8apply plugin: 'signing'
9
10// todo: figure out how we can check it in a generic way
11def isMultiplatform = project.name == 'atomicfu'
12
13if (!isMultiplatform) {
14    // Regular java modules need 'java-library' plugin for proper publication
15    apply plugin: 'java-library'
16
17    // MPP projects pack their sources automtically, java libraries need to explicitly pack them
18    task sourcesJar(type: Jar) {
19        archiveClassifier = 'sources'
20        from "src/main/kotlin"
21    }
22}
23
24// empty xxx-javadoc.jar
25task javadocJar(type: Jar) {
26    archiveClassifier = 'javadoc'
27}
28
29publishing {
30    repositories { // this: closure
31        PublishingKt.configureMavenPublication(delegate, project)
32    }
33
34    if (!isMultiplatform) {
35        // Configure java publications for non-MPP projects
36        publications {
37            // plugin configures its own publication pluginMaven
38            if (project.name == 'atomicfu-gradle-plugin') {
39                pluginMaven(MavenPublication) {
40                    artifact sourcesJar
41                }
42            } else {
43                maven(MavenPublication) {
44                    from components.java
45                    artifact sourcesJar
46
47                    if (project.name.endsWith("-maven-plugin")) {
48                        pom.packaging = 'maven-plugin'
49                    }
50                }
51            }
52        }
53    }
54
55    publications.all {
56        PublishingKt.configureMavenCentralMetadata(pom, project)
57        PublishingKt.signPublicationIfKeyPresent(project, it)
58        // add empty javadocs
59        if (it.name != "kotlinMultiplatform") { // The root module gets the JVM's javadoc JAR
60            it.artifact(javadocJar)
61        }
62    }
63
64    tasks.withType(AbstractPublishToMaven).configureEach {
65        dependsOn(tasks.withType(Sign))
66    }
67
68    // NOTE: This is a temporary WA, see KT-61313.
69    tasks.withType(Sign).configureEach { signTask ->
70        def pubName = name.takeBetween("sign", "Publication")
71
72        // Task ':linkDebugTest<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
73        tasks.findByName("linkDebugTest$pubName")?.configure {
74            mustRunAfter(signTask)
75        }
76        // Task ':compileTestKotlin<platform>' uses this output of task ':sign<platform>Publication' without declaring an explicit or implicit dependency
77        tasks.findByName("compileTestKotlin$pubName")?.configure {
78            mustRunAfter(signTask)
79        }
80    }
81}
82