diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b2cfba1..d4c785e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -31,6 +31,27 @@ jobs: with: token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }} ref: develop + fetch-depth: 0 + + - name: Verify main is merged into develop + run: | + git fetch origin main + + # Check if main is fully merged into develop (i.e., main is an ancestor of develop) + if ! git merge-base --is-ancestor origin/main HEAD; then + echo "❌ Error: main branch has commits not in develop!" + echo "" + echo "This usually means someone pushed directly into main or a previous release pushed + echo "main but failed to push develop. You need to merge main into develop:" + echo "" + echo " git checkout develop" + echo " git merge origin/main" + echo " git push origin develop" + echo "" + echo "After fixing this, you can retry the release." + exit 1 + fi + echo "✅ main is fully merged into develop" - name: Bump version id: bump diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index fcf2674..443934f 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -48,6 +48,13 @@ gradlePlugin { description = "Convention plugin for Stream Android application modules" tags = listOf("android", "application", "convention", "stream", "kotlin") } + create("javaLibrary") { + id = "io.getstream.java.library" + implementationClass = "io.getstream.android.JavaLibraryConventionPlugin" + displayName = "Stream Java Library Convention Plugin" + description = "Convention plugin for Stream Java/Kotlin JVM library modules" + tags = listOf("java", "library", "convention", "stream", "kotlin") + } } } diff --git a/plugin/src/main/kotlin/io/getstream/android/BaseConfiguration.kt b/plugin/src/main/kotlin/io/getstream/android/BaseConfiguration.kt new file mode 100644 index 0000000..a31ec53 --- /dev/null +++ b/plugin/src/main/kotlin/io/getstream/android/BaseConfiguration.kt @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2014-2025 Stream.io Inc. All rights reserved. + * + * Licensed under the Stream License; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://github.com/GetStream/stream-build-conventions-android/blob/main/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.getstream.android + +import com.android.build.api.dsl.CommonExtension +import org.gradle.api.JavaVersion +import org.gradle.api.Project +import org.gradle.api.plugins.AppliedPlugin +import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.api.tasks.testing.Test +import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.gradle.kotlin.dsl.getByType +import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +private val javaVersion = JavaVersion.VERSION_11 +private val jvmTargetVersion = JvmTarget.JVM_11 + +internal inline fun > Project.configureAndroid() { + val commonExtension = extensions.getByType() + + commonExtension.apply { + compileOptions { + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + } + + testOptions { + unitTests { + isIncludeAndroidResources = true + isReturnDefaultValues = true + all(Test::configureTestLogging) + } + } + } + + tasks.withType().configureEach { + sourceCompatibility = javaVersion.toString() + targetCompatibility = javaVersion.toString() + } +} + +internal fun Project.configureJava() { + tasks.withType().configureEach { + sourceCompatibility = javaVersion.toString() + targetCompatibility = javaVersion.toString() + } + + tasks.withType().configureEach(Test::configureTestLogging) +} + +private fun Test.configureTestLogging() = testLogging { + events("failed") + showExceptions = true + showCauses = true + showStackTraces = true + exceptionFormat = TestExceptionFormat.FULL +} + +internal fun Project.configureKotlin() { + val configure = { _: AppliedPlugin -> + tasks.withType().configureEach { + compilerOptions { jvmTarget.set(jvmTargetVersion) } + } + } + + // Configure the Kotlin plugin that is applied, if any + pluginManager.withPlugin("org.jetbrains.kotlin.android", configure) + pluginManager.withPlugin("org.jetbrains.kotlin.jvm", configure) +} diff --git a/plugin/src/main/kotlin/io/getstream/android/StreamConventionPlugins.kt b/plugin/src/main/kotlin/io/getstream/android/StreamConventionPlugins.kt index 5634ce0..d1ac24b 100644 --- a/plugin/src/main/kotlin/io/getstream/android/StreamConventionPlugins.kt +++ b/plugin/src/main/kotlin/io/getstream/android/StreamConventionPlugins.kt @@ -16,17 +16,9 @@ package io.getstream.android import com.android.build.api.dsl.ApplicationExtension -import com.android.build.api.dsl.CommonExtension import com.android.build.api.dsl.LibraryExtension -import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.tasks.compile.JavaCompile -import org.gradle.api.tasks.testing.logging.TestExceptionFormat -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.dsl.JvmTarget -import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension class AndroidApplicationConventionPlugin : Plugin { override fun apply(target: Project) { @@ -34,6 +26,7 @@ class AndroidApplicationConventionPlugin : Plugin { pluginManager.apply("com.android.application") configureAndroid() + configureKotlin() } } } @@ -44,48 +37,18 @@ class AndroidLibraryConventionPlugin : Plugin { pluginManager.apply("com.android.library") configureAndroid() + configureKotlin() } } } -private val javaVersion = JavaVersion.VERSION_11 -private val jvmTargetVersion = JvmTarget.JVM_11 - -private inline fun > Project.configureAndroid() { - val commonExtension = extensions.getByType(Ext::class.java) - - commonExtension.apply { - compileOptions { - sourceCompatibility = javaVersion - targetCompatibility = javaVersion - } - - testOptions { - unitTests { - isIncludeAndroidResources = true - isReturnDefaultValues = true - all { - it.testLogging { - events("failed") - showExceptions = true - showCauses = true - showStackTraces = true - exceptionFormat = TestExceptionFormat.FULL - } - } - } - } - } - - tasks.withType().configureEach { - sourceCompatibility = javaVersion.toString() - targetCompatibility = javaVersion.toString() - } +class JavaLibraryConventionPlugin : Plugin { + override fun apply(target: Project) { + with(target) { + pluginManager.apply("java-library") - // Configure the Kotlin plugin if it is applied - pluginManager.withPlugin("org.jetbrains.kotlin.android") { - extensions.configure { - compilerOptions { jvmTarget.set(jvmTargetVersion) } + configureJava() + configureKotlin() } } }