|
| 1 | +package com.goalpanzi.mission_mate.convention |
| 2 | + |
| 3 | +import com.android.build.api.dsl.ApplicationExtension |
| 4 | +import com.android.build.api.dsl.CommonExtension |
| 5 | +import com.android.build.api.dsl.LibraryExtension |
| 6 | +import org.gradle.api.Project |
| 7 | +import org.gradle.api.artifacts.VersionCatalog |
| 8 | +import org.gradle.api.artifacts.VersionCatalogsExtension |
| 9 | +import org.gradle.api.artifacts.dsl.DependencyHandler |
| 10 | +import org.gradle.api.plugins.ExtensionContainer |
| 11 | +import org.gradle.kotlin.dsl.getByType |
| 12 | + |
| 13 | +internal val ExtensionContainer.libs: VersionCatalog |
| 14 | + get() = getByType<VersionCatalogsExtension>().named("libs") |
| 15 | + |
| 16 | +internal val Project.androidExtension: CommonExtension<*, *, *, *, *, *> |
| 17 | + get() = runCatching { libraryExtension } |
| 18 | + .recoverCatching { applicationExtension } |
| 19 | + .onFailure { println("Could not find Library or Application extension from this project") } |
| 20 | + .getOrThrow() |
| 21 | + |
| 22 | +internal val Project.applicationExtension: CommonExtension<*, *, *, *, *, *> |
| 23 | + get() = extensions.getByType<ApplicationExtension>() |
| 24 | + |
| 25 | +internal val Project.libraryExtension: CommonExtension<*, *, *, *, *, *> |
| 26 | + get() = extensions.getByType<LibraryExtension>() |
| 27 | + |
| 28 | +internal fun DependencyHandler.implementation(dependencyNotation: Any) { |
| 29 | + add("implementation", dependencyNotation) |
| 30 | +} |
| 31 | + |
| 32 | +internal fun DependencyHandler.testImplementation(dependencyNotation: Any) { |
| 33 | + add("testImplementation", dependencyNotation) |
| 34 | +} |
| 35 | + |
| 36 | +internal fun DependencyHandler.androidTestImplementation(dependencyNotation: Any) { |
| 37 | + add("androidTestImplementation", dependencyNotation) |
| 38 | +} |
| 39 | + |
| 40 | +internal fun DependencyHandler.debugImplementation(dependencyNotation: Any) { |
| 41 | + add("debugImplementation", dependencyNotation) |
| 42 | +} |
| 43 | + |
| 44 | +internal fun DependencyHandler.ksp(dependencyNotation: Any) { |
| 45 | + add("ksp", dependencyNotation) |
| 46 | +} |
0 commit comments