1
- import com.android.build.gradle.TestedExtension
2
- import com.squareup.workflow1.library
3
- import com.squareup.workflow1.libsCatalog
1
+ @file:Suppress(" UnstableApiUsage" )
2
+
3
+ import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
4
+ import com.vanniktech.maven.publish.JavadocJar.Dokka
5
+ import com.vanniktech.maven.publish.KotlinJvm
6
+ import com.vanniktech.maven.publish.KotlinMultiplatform
7
+ import com.vanniktech.maven.publish.MavenPublishBaseExtension
4
8
import com.vanniktech.maven.publish.SonatypeHost
5
9
6
10
plugins {
7
11
id(" org.jetbrains.dokka" )
8
- id(" com.vanniktech.maven.publish" )
12
+ id(" com.vanniktech.maven.publish.base " )
9
13
// track all runtime classpath dependencies for anything we ship
10
14
id(" dependency-guard" )
11
15
}
12
16
13
- group = project.property(" GROUP" ) as String
14
17
version = project.property(" VERSION_NAME" ) as String
15
18
16
- mavenPublish {
17
- sonatypeHost = SonatypeHost .S01
18
- }
19
-
20
19
tasks.register(" checkVersionIsSnapshot" ) {
21
20
doLast {
22
21
val expected = " -SNAPSHOT"
@@ -26,3 +25,62 @@ tasks.register("checkVersionIsSnapshot") {
26
25
}
27
26
}
28
27
}
28
+
29
+ configure<MavenPublishBaseExtension > {
30
+ publishToMavenCentral(SonatypeHost .S01 )
31
+ // Will only apply to non snapshot builds.
32
+ signAllPublications()
33
+ // import all settings from root project and project-specific gradle.properties files
34
+ pomFromGradleProperties()
35
+
36
+ val artifactId = project.property(" POM_ARTIFACT_ID" ) as String
37
+ val pomDescription = project.property(" POM_NAME" ) as String
38
+
39
+ pluginManager.withPlugin(" com.android.library" ) {
40
+ configure(AndroidSingleVariantLibrary (sourcesJar = true ))
41
+ setPublicationProperties(pomDescription, artifactId)
42
+ }
43
+ pluginManager.withPlugin(" org.jetbrains.kotlin.jvm" ) {
44
+ configure(KotlinJvm (javadocJar = Dokka (taskName = " dokkaGfm" ), sourcesJar = true ))
45
+ setPublicationProperties(pomDescription, artifactId)
46
+ }
47
+ pluginManager.withPlugin(" org.jetbrains.kotlin.multiplatform" ) {
48
+ configure(KotlinMultiplatform (javadocJar = Dokka (taskName = " dokkaGfm" )))
49
+ // don't set the artifactId for KMP, because this is handled by the KMP plugin itself
50
+ setPublicationProperties(pomDescription, artifactIdOrNull = null )
51
+ }
52
+ }
53
+
54
+ fun setPublicationProperties (
55
+ pomDescription : String ,
56
+ artifactIdOrNull : String?
57
+ ) {
58
+ // This has to be inside an `afterEvaluate { }` because these publications are created lazily,
59
+ // using the project's `name`, which is just the directory name instead of the actual artifact id.
60
+ // We can't set `name` because it's immutable, so we have to wait until the publication is
61
+ // created, then overwrite the incorrect value.
62
+ afterEvaluate {
63
+ configure<PublishingExtension > {
64
+ publications.filterIsInstance<MavenPublication >()
65
+ .forEach { publication ->
66
+
67
+ if (artifactIdOrNull != null ) {
68
+ publication.artifactId = artifactIdOrNull
69
+ }
70
+ publication.pom.description.set(pomDescription)
71
+
72
+ // Note that we're setting the `groupId` of this specific publication,
73
+ // and not `Project.group`. By default, `Project.group` is a project's parent,
74
+ // so for example the group of `:workflow-ui:compose` is `workflow-ui`. If we set every
75
+ // project's `group` to the group id, then we use the natural disambiguation of unique
76
+ // paths. For instance, projects with paths of `:lib1:core` and `:lib2:core`
77
+ // and a group of `com.example` would both have the coordinates of `com.example:core`.
78
+ publication.groupId = project.property(" GROUP" ) as String
79
+ }
80
+ }
81
+ }
82
+ }
83
+
84
+ tasks.withType(PublishToMavenRepository ::class .java).configureEach {
85
+ notCompatibleWithConfigurationCache(" See https://github.com/gradle/gradle/issues/13468" )
86
+ }
0 commit comments