Skip to content

Commit

Permalink
Migrate to Gradle version catalogs. (#1129)
Browse files Browse the repository at this point in the history
* Migrate to Gradle version catalogs.

* Migrate more.

* Fixes.

* Remove dependencies.

* Fix test.

* Bump.

* Rename.

* Reduce dependencies.

* Clean up.

* Reverse order.

* Remove plugins.gradle.kts.

* Revert "Remove plugins.gradle.kts."

This reverts commit ac623a4.

* Formatting.
  • Loading branch information
colinrtwhite authored Feb 9, 2022
1 parent cc54de3 commit d5c7ca9
Show file tree
Hide file tree
Showing 36 changed files with 238 additions and 310 deletions.
49 changes: 0 additions & 49 deletions buildSrc/src/main/kotlin/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
package coil

import org.gradle.api.Project
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.dsl.DependencyHandler
import org.gradle.api.provider.Property
import org.gradle.api.provider.SetProperty
import org.gradle.kotlin.dsl.kotlin
import org.gradle.kotlin.dsl.project
import kotlin.math.pow

val Project.minSdk: Int
Expand Down Expand Up @@ -54,51 +50,6 @@ private inline fun <T> List<T>.sumByIndexed(selector: (Int, T) -> Int): Int {
return sum
}

private fun DependencyHandler.testImplementation(dependencyNotation: Any): Dependency? {
return add("testImplementation", dependencyNotation)
}

private fun DependencyHandler.androidTestImplementation(dependencyNotation: Any): Dependency? {
return add("androidTestImplementation", dependencyNotation)
}

fun DependencyHandler.addTestDependencies(kotlinVersion: String) {
testImplementation(project(":coil-test"))

testImplementation(Library.JUNIT)
testImplementation(kotlin("test-junit", kotlinVersion))

testImplementation(Library.KOTLINX_COROUTINES_TEST)

testImplementation(Library.ANDROIDX_TEST_CORE)
testImplementation(Library.ANDROIDX_TEST_JUNIT)
testImplementation(Library.ANDROIDX_TEST_RULES)
testImplementation(Library.ANDROIDX_TEST_RUNNER)

testImplementation(Library.OKHTTP_MOCK_WEB_SERVER)
testImplementation(Library.OKIO_FAKE_FILESYSTEM)

testImplementation(Library.ROBOLECTRIC)
}

fun DependencyHandler.addAndroidTestDependencies(kotlinVersion: String) {
androidTestImplementation(project(":coil-test"))

androidTestImplementation(Library.JUNIT)
androidTestImplementation(kotlin("test-junit", kotlinVersion))

androidTestImplementation(Library.KOTLINX_COROUTINES_TEST)

androidTestImplementation(Library.MATERIAL)

androidTestImplementation(Library.ANDROIDX_TEST_CORE)
androidTestImplementation(Library.ANDROIDX_TEST_JUNIT)
androidTestImplementation(Library.ANDROIDX_TEST_RULES)
androidTestImplementation(Library.ANDROIDX_TEST_RUNNER)

androidTestImplementation(Library.OKHTTP_MOCK_WEB_SERVER)
}

inline infix fun <T> Property<T>.by(value: T) = set(value)

inline infix fun <T> SetProperty<T>.by(value: Set<T>) = set(value)
59 changes: 0 additions & 59 deletions buildSrc/src/main/kotlin/Library.kt

This file was deleted.

117 changes: 54 additions & 63 deletions buildSrc/src/main/kotlin/Projects.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,69 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions
fun Project.setupLibraryModule(
enableBuildConfig: Boolean = false,
block: LibraryExtension.() -> Unit = {}
) {
setupBaseModule<LibraryExtension> {
if (!enableBuildConfig) {
libraryVariants.all {
generateBuildConfigProvider?.configure { enabled = false }
}
}
packagingOptions {
// https://github.com/Kotlin/kotlinx.coroutines/issues/2023
resources.pickFirsts += "META-INF/AL2.0"
resources.pickFirsts += "META-INF/LGPL2.1"
}
testOptions {
unitTests.isIncludeAndroidResources = true
}
block()
) = setupBaseModule<LibraryExtension> {
libraryVariants.all {
generateBuildConfigProvider?.configure { enabled = enableBuildConfig }
}
block()
}

fun Project.setupAppModule(block: BaseAppModuleExtension.() -> Unit = {}) {
setupBaseModule<BaseAppModuleExtension> {
defaultConfig {
versionCode = project.versionCode
versionName = project.versionName
resourceConfigurations += "en"
vectorDrawables.useSupportLibrary = true
}
block()
fun Project.setupAppModule(
block: BaseAppModuleExtension.() -> Unit = {}
) = setupBaseModule<BaseAppModuleExtension> {
defaultConfig {
versionCode = project.versionCode
versionName = project.versionName
resourceConfigurations += "en"
vectorDrawables.useSupportLibrary = true
}
block()
}

private inline fun <reified T : BaseExtension> Project.setupBaseModule(crossinline block: T.() -> Unit = {}) {
extensions.configure<BaseExtension>("android") {
compileSdkVersion(project.compileSdk)
defaultConfig {
minSdk = project.minSdk
targetSdk = project.targetSdk
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
allWarningsAsErrors = true
private inline fun <reified T : BaseExtension> Project.setupBaseModule(
crossinline block: T.() -> Unit = {}
) = extensions.configure<T>("android") {
compileSdkVersion(project.compileSdk)
defaultConfig {
minSdk = project.minSdk
targetSdk = project.targetSdk
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
allWarningsAsErrors = true

val arguments = mutableListOf(
// https://kotlinlang.org/docs/compiler-reference.html#progressive
"-progressive",
// Generate native Java 8 default interface methods.
"-Xjvm-default=all",
// Generate smaller bytecode by not generating runtime not-null assertions.
"-Xno-call-assertions",
"-Xno-param-assertions",
"-Xno-receiver-assertions",
// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-requires-opt-in/#requiresoptin
"-Xopt-in=kotlin.RequiresOptIn"
)
if (project.name != "coil-test") {
arguments += "-Xopt-in=coil.annotation.ExperimentalCoilApi"
}
// https://youtrack.jetbrains.com/issue/KT-41985
freeCompilerArgs += arguments
}
packagingOptions {
resources.pickFirsts += "META-INF/AL2.0"
resources.pickFirsts += "META-INF/LGPL2.1"
resources.pickFirsts += "META-INF/*kotlin_module"
val arguments = mutableListOf(
// https://kotlinlang.org/docs/compiler-reference.html#progressive
"-progressive",
// Generate native Java 8 default interface methods.
"-Xjvm-default=all",
// Generate smaller bytecode by not generating runtime not-null assertions.
"-Xno-call-assertions",
"-Xno-param-assertions",
"-Xno-receiver-assertions",
// https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-requires-opt-in/#requiresoptin
"-Xopt-in=kotlin.RequiresOptIn"
)
if (project.name != "coil-test") {
arguments += "-Xopt-in=coil.annotation.ExperimentalCoilApi"
}
(this as T).block()
// https://youtrack.jetbrains.com/issue/KT-41985
freeCompilerArgs += arguments
}
packagingOptions {
resources.pickFirsts += "META-INF/AL2.0"
resources.pickFirsts += "META-INF/LGPL2.1"
resources.pickFirsts += "META-INF/*kotlin_module"
}
testOptions {
unitTests.isIncludeAndroidResources = true
}
block()
}

private fun BaseExtension.kotlinOptions(block: KotlinJvmOptions.() -> Unit) {
Expand Down
37 changes: 14 additions & 23 deletions coil-base/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import coil.Library
import coil.addAndroidTestDependencies
import coil.addTestDependencies
import coil.setupLibraryModule
import org.jetbrains.kotlin.config.KotlinCompilerVersion

plugins {
id("com.android.library")
Expand All @@ -12,27 +8,22 @@ plugins {
id("com.vanniktech.maven.publish")
}

setupLibraryModule {
sourceSets {
getByName("test").java.srcDir("src/sharedTest/java")
getByName("androidTest").java.srcDir("src/sharedTest/java")
}
}
setupLibraryModule()

dependencies {
api(kotlin("stdlib-jdk8", KotlinCompilerVersion.VERSION))
api(Library.KOTLINX_COROUTINES_ANDROID)

implementation(Library.ANDROIDX_ANNOTATION)
implementation(Library.ANDROIDX_APPCOMPAT_RESOURCES)
implementation(Library.ANDROIDX_COLLECTION)
implementation(Library.ANDROIDX_CORE)
implementation(Library.ANDROIDX_EXIF_INTERFACE)
api(Library.ANDROIDX_LIFECYCLE_RUNTIME)
implementation(libs.androidx.annotation)
implementation(libs.androidx.appcompat.resources)
implementation(libs.androidx.collection)
implementation(libs.androidx.core)
implementation(libs.androidx.exifinterface)
api(libs.androidx.lifecycle.runtime)
api(libs.coroutines.android)
api(libs.okhttp)
api(libs.okio)

api(Library.OKHTTP)
api(Library.OKIO)
testImplementation(project(":coil-test"))
testImplementation(libs.bundles.test.jvm)

addTestDependencies(KotlinCompilerVersion.VERSION)
addAndroidTestDependencies(KotlinCompilerVersion.VERSION)
androidTestImplementation(project(":coil-test"))
androidTestImplementation(libs.bundles.test.android)
}
2 changes: 1 addition & 1 deletion coil-base/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>

<application android:usesCleartextTraffic="true">
<application>
<provider
android:name="coil.util.AssetContentProvider"
android:authorities="coil"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import coil.util.getDrawableCompat
import coil.util.isMainThread
import coil.util.runTestAsync
import coil.util.runTestMain
import coil.util.size
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import androidx.test.core.app.ApplicationProvider
import coil.ImageLoader
import coil.fetch.SourceResult
import coil.request.Options
import coil.size
import coil.size.Dimension
import coil.size.Scale
import coil.size.Size
import coil.util.assertIsSimilarTo
import coil.util.assumeTrue
import coil.util.decodeBitmapAsset
import coil.util.isSimilarTo
import coil.util.size
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import okio.buffer
Expand Down
4 changes: 1 addition & 3 deletions coil-base/src/androidTest/res/drawable/ic_tinted_vector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?colorPrimary"
android:tintMode="src_in">
android:viewportHeight="24.0">
<path
android:fillColor="#FF0000"
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
Expand Down
7 changes: 0 additions & 7 deletions coil-base/src/sharedTest/java/coil/SharedTestFunctions.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import coil.intercept.EngineInterceptor.ExecuteResult
import coil.key.Keyer
import coil.request.Options
import coil.request.RequestService
import coil.size
import coil.size.Size
import coil.transform.CircleCropTransformation
import coil.util.SystemCallbacks
import coil.util.createRequest
import coil.util.size
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
Expand Down
1 change: 0 additions & 1 deletion coil-base/src/test/java/coil/util/DrawableUtilsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.core.graphics.component3
import androidx.core.graphics.component4
import androidx.test.core.app.ApplicationProvider
import coil.base.R
import coil.size
import coil.size.Scale
import coil.size.Size
import org.junit.Test
Expand Down
Loading

0 comments on commit d5c7ca9

Please # to comment.