Skip to content

Commit 84de0fc

Browse files
authored
Introduce Java library Stream plugin (#3)
* Introduce Java library Stream plugin * Extract base configuration to separate file * Remove kotlin plugin application from java library * Check develop and main are in sync at the start of the release workflow
1 parent 13235a4 commit 84de0fc

File tree

4 files changed

+120
-45
lines changed

4 files changed

+120
-45
lines changed

.github/workflows/release.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@ jobs:
3131
with:
3232
token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}
3333
ref: develop
34+
fetch-depth: 0
35+
36+
- name: Verify main is merged into develop
37+
run: |
38+
git fetch origin main
39+
40+
# Check if main is fully merged into develop (i.e., main is an ancestor of develop)
41+
if ! git merge-base --is-ancestor origin/main HEAD; then
42+
echo "❌ Error: main branch has commits not in develop!"
43+
echo ""
44+
echo "This usually means someone pushed directly into main or a previous release pushed
45+
echo "main but failed to push develop. You need to merge main into develop:"
46+
echo ""
47+
echo " git checkout develop"
48+
echo " git merge origin/main"
49+
echo " git push origin develop"
50+
echo ""
51+
echo "After fixing this, you can retry the release."
52+
exit 1
53+
fi
54+
echo "✅ main is fully merged into develop"
3455
3556
- name: Bump version
3657
id: bump

plugin/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ gradlePlugin {
4848
description = "Convention plugin for Stream Android application modules"
4949
tags = listOf("android", "application", "convention", "stream", "kotlin")
5050
}
51+
create("javaLibrary") {
52+
id = "io.getstream.java.library"
53+
implementationClass = "io.getstream.android.JavaLibraryConventionPlugin"
54+
displayName = "Stream Java Library Convention Plugin"
55+
description = "Convention plugin for Stream Java/Kotlin JVM library modules"
56+
tags = listOf("java", "library", "convention", "stream", "kotlin")
57+
}
5158
}
5259
}
5360

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 com.android.build.api.dsl.CommonExtension
19+
import org.gradle.api.JavaVersion
20+
import org.gradle.api.Project
21+
import org.gradle.api.plugins.AppliedPlugin
22+
import org.gradle.api.tasks.compile.JavaCompile
23+
import org.gradle.api.tasks.testing.Test
24+
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
25+
import org.gradle.kotlin.dsl.getByType
26+
import org.gradle.kotlin.dsl.withType
27+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
28+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
29+
30+
private val javaVersion = JavaVersion.VERSION_11
31+
private val jvmTargetVersion = JvmTarget.JVM_11
32+
33+
internal inline fun <reified Ext : CommonExtension<*, *, *, *, *, *>> Project.configureAndroid() {
34+
val commonExtension = extensions.getByType<Ext>()
35+
36+
commonExtension.apply {
37+
compileOptions {
38+
sourceCompatibility = javaVersion
39+
targetCompatibility = javaVersion
40+
}
41+
42+
testOptions {
43+
unitTests {
44+
isIncludeAndroidResources = true
45+
isReturnDefaultValues = true
46+
all(Test::configureTestLogging)
47+
}
48+
}
49+
}
50+
51+
tasks.withType<JavaCompile>().configureEach {
52+
sourceCompatibility = javaVersion.toString()
53+
targetCompatibility = javaVersion.toString()
54+
}
55+
}
56+
57+
internal fun Project.configureJava() {
58+
tasks.withType<JavaCompile>().configureEach {
59+
sourceCompatibility = javaVersion.toString()
60+
targetCompatibility = javaVersion.toString()
61+
}
62+
63+
tasks.withType<Test>().configureEach(Test::configureTestLogging)
64+
}
65+
66+
private fun Test.configureTestLogging() = testLogging {
67+
events("failed")
68+
showExceptions = true
69+
showCauses = true
70+
showStackTraces = true
71+
exceptionFormat = TestExceptionFormat.FULL
72+
}
73+
74+
internal fun Project.configureKotlin() {
75+
val configure = { _: AppliedPlugin ->
76+
tasks.withType<KotlinCompile>().configureEach {
77+
compilerOptions { jvmTarget.set(jvmTargetVersion) }
78+
}
79+
}
80+
81+
// Configure the Kotlin plugin that is applied, if any
82+
pluginManager.withPlugin("org.jetbrains.kotlin.android", configure)
83+
pluginManager.withPlugin("org.jetbrains.kotlin.jvm", configure)
84+
}

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

Lines changed: 8 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,17 @@
1616
package io.getstream.android
1717

1818
import com.android.build.api.dsl.ApplicationExtension
19-
import com.android.build.api.dsl.CommonExtension
2019
import com.android.build.api.dsl.LibraryExtension
21-
import org.gradle.api.JavaVersion
2220
import org.gradle.api.Plugin
2321
import org.gradle.api.Project
24-
import org.gradle.api.tasks.compile.JavaCompile
25-
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
26-
import org.gradle.kotlin.dsl.configure
27-
import org.gradle.kotlin.dsl.withType
28-
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
29-
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
3022

3123
class AndroidApplicationConventionPlugin : Plugin<Project> {
3224
override fun apply(target: Project) {
3325
with(target) {
3426
pluginManager.apply("com.android.application")
3527

3628
configureAndroid<ApplicationExtension>()
29+
configureKotlin()
3730
}
3831
}
3932
}
@@ -44,48 +37,18 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
4437
pluginManager.apply("com.android.library")
4538

4639
configureAndroid<LibraryExtension>()
40+
configureKotlin()
4741
}
4842
}
4943
}
5044

51-
private val javaVersion = JavaVersion.VERSION_11
52-
private val jvmTargetVersion = JvmTarget.JVM_11
53-
54-
private inline fun <reified Ext : CommonExtension<*, *, *, *, *, *>> Project.configureAndroid() {
55-
val commonExtension = extensions.getByType(Ext::class.java)
56-
57-
commonExtension.apply {
58-
compileOptions {
59-
sourceCompatibility = javaVersion
60-
targetCompatibility = javaVersion
61-
}
62-
63-
testOptions {
64-
unitTests {
65-
isIncludeAndroidResources = true
66-
isReturnDefaultValues = true
67-
all {
68-
it.testLogging {
69-
events("failed")
70-
showExceptions = true
71-
showCauses = true
72-
showStackTraces = true
73-
exceptionFormat = TestExceptionFormat.FULL
74-
}
75-
}
76-
}
77-
}
78-
}
79-
80-
tasks.withType<JavaCompile>().configureEach {
81-
sourceCompatibility = javaVersion.toString()
82-
targetCompatibility = javaVersion.toString()
83-
}
45+
class JavaLibraryConventionPlugin : Plugin<Project> {
46+
override fun apply(target: Project) {
47+
with(target) {
48+
pluginManager.apply("java-library")
8449

85-
// Configure the Kotlin plugin if it is applied
86-
pluginManager.withPlugin("org.jetbrains.kotlin.android") {
87-
extensions.configure<KotlinAndroidProjectExtension> {
88-
compilerOptions { jvmTarget.set(jvmTargetVersion) }
50+
configureJava()
51+
configureKotlin()
8952
}
9053
}
9154
}

0 commit comments

Comments
 (0)