Skip to content

Commit 55564c3

Browse files
committed
Extract base configuration to separate file
1 parent 4d51bae commit 55564c3

File tree

2 files changed

+84
-67
lines changed

2 files changed

+84
-67
lines changed
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: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,9 @@
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.plugins.AppliedPlugin
25-
import org.gradle.api.tasks.compile.JavaCompile
26-
import org.gradle.api.tasks.testing.Test
27-
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
28-
import org.gradle.kotlin.dsl.getByType
29-
import org.gradle.kotlin.dsl.withType
30-
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
31-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
3222

3323
class AndroidApplicationConventionPlugin : Plugin<Project> {
3424
override fun apply(target: Project) {
@@ -63,60 +53,3 @@ class JavaLibraryConventionPlugin : Plugin<Project> {
6353
}
6454
}
6555
}
66-
67-
private val javaVersion = JavaVersion.VERSION_11
68-
private val jvmTargetVersion = JvmTarget.JVM_11
69-
70-
private inline fun <reified Ext : CommonExtension<*, *, *, *, *, *>> Project.configureAndroid() {
71-
val commonExtension = extensions.getByType<Ext>()
72-
73-
commonExtension.apply {
74-
compileOptions {
75-
sourceCompatibility = javaVersion
76-
targetCompatibility = javaVersion
77-
}
78-
79-
testOptions {
80-
unitTests {
81-
isIncludeAndroidResources = true
82-
isReturnDefaultValues = true
83-
all(Test::configureTestLogging)
84-
}
85-
}
86-
}
87-
88-
tasks.withType<JavaCompile>().configureEach {
89-
sourceCompatibility = javaVersion.toString()
90-
targetCompatibility = javaVersion.toString()
91-
}
92-
}
93-
94-
private fun Project.configureJava() {
95-
tasks.withType<JavaCompile>().configureEach {
96-
sourceCompatibility = javaVersion.toString()
97-
targetCompatibility = javaVersion.toString()
98-
}
99-
100-
tasks.withType<Test>().configureEach(Test::configureTestLogging)
101-
}
102-
103-
private fun Test.configureTestLogging() = testLogging {
104-
events("failed")
105-
showExceptions = true
106-
showCauses = true
107-
showStackTraces = true
108-
exceptionFormat = TestExceptionFormat.FULL
109-
}
110-
111-
private fun Project.configureKotlin() {
112-
val configure =
113-
fun(_: AppliedPlugin) {
114-
tasks.withType<KotlinCompile>().configureEach {
115-
compilerOptions { jvmTarget.set(jvmTargetVersion) }
116-
}
117-
}
118-
119-
// Configure the Kotlin plugin that is applied, if any
120-
pluginManager.withPlugin("org.jetbrains.kotlin.android", configure)
121-
pluginManager.withPlugin("org.jetbrains.kotlin.jvm", configure)
122-
}

0 commit comments

Comments
 (0)