Skip to content

Commit effbeaa

Browse files
committed
Add publishing configuration to plugins
1 parent d5c3a65 commit effbeaa

File tree

9 files changed

+347
-31
lines changed

9 files changed

+347
-31
lines changed

README.md

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,18 @@ configurations to ensure consistency across Stream's Android libraries and appli
66
> **Note:** These plugins are designed specifically for Stream's projects and workflows. They aren't
77
> intended for general-purpose use and may include Stream-specific configurations and conventions.
88
9-
## Overview
10-
11-
This repository contains reusable Gradle convention plugins that encapsulate common build logic,
12-
dependencies, and configurations used across Stream's Android projects.
13-
149
## Available Plugins
1510

1611
- **`io.getstream.project`** - Root project configuration (apply to root `build.gradle.kts`)
17-
- **`io.getstream.android.library`** - For Android library modules
18-
- **`io.getstream.android.application`** - For Android application modules
19-
- **`io.getstream.android.test`** - For Android test modules
20-
- **`io.getstream.java.library`** - For Java/Kotlin JVM library modules
12+
- **`io.getstream.android.library`** - Android library modules
13+
- **`io.getstream.android.application`** - Android application modules
14+
- **`io.getstream.android.test`** - Android test modules
15+
- **`io.getstream.java.library`** - Java/Kotlin JVM library modules
16+
- **`io.getstream.java.platform`** - Java/Kotlin JVM platform modules
2117

2218
## Usage
2319

24-
### 1. Root Project Configuration
20+
### Root Project Setup
2521

2622
Apply the root plugin in your root `build.gradle.kts`:
2723

@@ -31,35 +27,74 @@ plugins {
3127
}
3228

3329
streamProject {
34-
// Repository name for GitHub URLs and license headers (default: project name)
30+
// Repository name for GitHub URLs (default: project name)
3531
repositoryName = "stream-chat-android"
3632

3733
spotless {
38-
// Choose formatter (default: false = ktlint)
34+
// Choose formatter: true for ktfmt, false for ktlint (default: false)
3935
useKtfmt = false
4036

41-
// Exclude specific modules from Spotless formatting (default: empty)
37+
// Exclude specific modules from formatting (default: empty)
4238
ignoredModules = setOf("some-module")
4339

44-
// Exclude file patterns from Spotless formatting (default: empty)
40+
// Exclude file patterns from formatting (default: empty)
4541
excludePatterns = setOf("**/generated/**")
4642
}
43+
44+
publishing {
45+
// Required: Description for all published artifacts
46+
description = "Magical Stream SDK"
47+
48+
// Optional: Override artifact IDs for specific modules
49+
moduleArtifactIdOverrides = mapOf(
50+
"my-module" to "custom-artifact-id"
51+
)
52+
}
4753
}
4854
```
4955

50-
### 2. Module Configuration
56+
### Module Setup
5157

5258
Apply the appropriate plugin to each module:
5359

5460
```kotlin
5561
plugins {
5662
id("io.getstream.android.library")
57-
// or id("io.getstream.android.application")
58-
// or id("io.getstream.android.test")
59-
// or id("io.getstream.java.library")
63+
// or: id("io.getstream.android.application")
64+
// or: id("io.getstream.android.test")
65+
// or: id("io.getstream.java.library")
66+
// or: id("io.getstream.java.platform")
6067
}
6168
```
6269

70+
Library and platform plugins automatically configure Maven publishing.
71+
72+
## Versioning
73+
74+
Version is read from the project version. Can be set, for example, by adding it to
75+
`gradle.properties`:
76+
77+
```properties
78+
version=1.0.0
79+
```
80+
81+
All published modules use this version. For snapshot builds, set the `SNAPSHOT` environment
82+
variable:
83+
84+
```bash
85+
SNAPSHOT=true ./gradlew publish
86+
```
87+
88+
This produces timestamped snapshot versions: `1.0.0-yyyyMMddHHmm-SNAPSHOT`
89+
90+
## Publishing
91+
92+
Published artifacts use:
93+
94+
- **Group ID**: `io.getstream`
95+
- **Artifact ID**: Module name (or override via `moduleArtifactIdOverrides`)
96+
- **Version**: From `gradle.properties`
97+
6398
## License
6499

65100
See [LICENSE](LICENSE) file for details.

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ kotlin = "2.0.21"
44
detekt = "1.23.8"
55
spotless = "8.0.0"
66
kotlinDokka = "2.0.0"
7-
gradlePluginPublish = "2.0.0"
87
mavenPublish = "0.34.0"
98

109
[libraries]
1110
android-gradle-plugin = { group = "com.android.tools.build", name = "gradle", version.ref = "agp" }
1211
kotlin-gradle-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
1312
spotless-gradle-plugin = { group = "com.diffplug.spotless", name = "spotless-plugin-gradle", version.ref = "spotless" }
13+
maven-publish-gradle-plugin = { group = "com.vanniktech", name = "gradle-maven-publish-plugin", version.ref = "mavenPublish" }
14+
dokka-gradle-plugin = { group = "org.jetbrains.dokka", name = "dokka-gradle-plugin", version.ref = "kotlinDokka" }
1415

1516
[plugins]
1617
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
1718
dokka = { id = "org.jetbrains.dokka-javadoc", version.ref = "kotlinDokka" }
18-
gradle-plugin-publish = { id = "com.gradle.plugin-publish", version.ref = "gradlePluginPublish" }
1919
maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" }
2020
detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" }
2121
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }

plugin/build.gradle.kts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ dependencies {
2424
compileOnly(libs.android.gradle.plugin)
2525
compileOnly(libs.kotlin.gradle.plugin)
2626
implementation(libs.spotless.gradle.plugin)
27+
implementation(libs.maven.publish.gradle.plugin)
28+
implementation(libs.dokka.gradle.plugin)
2729
}
2830

2931
val repoId = "GetStream/stream-build-conventions-android"
@@ -70,12 +72,19 @@ gradlePlugin {
7072
description = "Convention plugin for Stream Java/Kotlin JVM library modules"
7173
tags = listOf("java", "library", "convention", "stream", "kotlin")
7274
}
75+
create("javaPlatform") {
76+
id = "io.getstream.java.platform"
77+
implementationClass = "io.getstream.android.JavaPlatformConventionPlugin"
78+
displayName = "Stream Java Platform Convention Plugin"
79+
description = "Convention plugin for Stream Java/Kotlin JVM platform modules"
80+
tags = listOf("java", "platform", "convention", "stream", "kotlin")
81+
}
7382
}
7483
}
7584

7685
mavenPublishing {
7786
publishToMavenCentral(automaticRelease = true)
78-
configure(GradlePlugin(javadocJar = JavadocJar.Javadoc(), sourcesJar = true))
87+
configure(GradlePlugin(javadocJar = JavadocJar.Dokka("dokkaGenerate"), sourcesJar = true))
7988

8089
pom {
8190
name.set("Stream Build Conventions")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-build-conventions-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.getstream.android
17+
18+
import org.gradle.api.Task
19+
import org.gradle.api.tasks.TaskContainer
20+
import org.gradle.kotlin.dsl.named
21+
import org.gradle.kotlin.dsl.register
22+
23+
internal inline fun <reified T : Task> TaskContainer.findOrRegister(
24+
name: String,
25+
noinline configuration: T.() -> Unit,
26+
) = findByName(name)?.let { named<T>(name) } ?: register<T>(name, configuration)

plugin/src/main/kotlin/io/getstream/android/StreamConventionExtensions.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package io.getstream.android
1717

18+
import io.getstream.android.publishing.PublishingOptions
1819
import io.getstream.android.spotless.SpotlessOptions
1920
import javax.inject.Inject
2021
import org.gradle.api.Action
@@ -23,6 +24,7 @@ import org.gradle.api.model.ObjectFactory
2324
import org.gradle.api.provider.Property
2425
import org.gradle.kotlin.dsl.create
2526
import org.gradle.kotlin.dsl.findByType
27+
import org.gradle.kotlin.dsl.newInstance
2628
import org.gradle.kotlin.dsl.property
2729

2830
/**
@@ -38,10 +40,16 @@ constructor(project: Project, objects: ObjectFactory) {
3840
objects.property<String>().convention(project.provider { project.rootProject.name })
3941

4042
/** Spotless formatting configuration */
41-
val spotless: SpotlessOptions = objects.newInstance(SpotlessOptions::class.java)
43+
val spotless: SpotlessOptions = objects.newInstance<SpotlessOptions>()
4244

4345
/** Configure Spotless formatting */
4446
fun spotless(action: Action<SpotlessOptions>) = action.execute(spotless)
47+
48+
/** Publishing configuration */
49+
val publishing: PublishingOptions = objects.newInstance<PublishingOptions>()
50+
51+
/** Configure publishing */
52+
fun publishing(action: Action<PublishingOptions>) = action.execute(publishing)
4553
}
4654

4755
internal fun Project.createProjectExtension(): StreamProjectExtension =

plugin/src/main/kotlin/io/getstream/android/StreamConventionPlugins.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package io.getstream.android
1818
import com.android.build.api.dsl.ApplicationExtension
1919
import com.android.build.api.dsl.LibraryExtension
2020
import com.android.build.api.dsl.TestExtension
21+
import io.getstream.android.publishing.configurePublishing
2122
import io.getstream.android.spotless.configureSpotless
2223
import org.gradle.api.Plugin
2324
import org.gradle.api.Project
@@ -58,6 +59,7 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
5859
configureAndroid<LibraryExtension>()
5960
configureKotlin()
6061
configureSpotless()
62+
configurePublishing()
6163
}
6264
}
6365
}
@@ -82,6 +84,20 @@ class JavaLibraryConventionPlugin : Plugin<Project> {
8284
configureJava()
8385
configureKotlin()
8486
configureSpotless()
87+
configurePublishing()
88+
}
89+
}
90+
}
91+
92+
class JavaPlatformConventionPlugin : Plugin<Project> {
93+
override fun apply(target: Project) {
94+
with(target) {
95+
pluginManager.apply("java-platform")
96+
97+
configureJava()
98+
configureKotlin()
99+
configureSpotless()
100+
configurePublishing()
85101
}
86102
}
87103
}

0 commit comments

Comments
 (0)