|
| 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 | +} |
0 commit comments