init projects
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package ru.shadowsparky
|
||||
|
||||
import com.android.build.api.dsl.ApplicationExtension
|
||||
import com.android.build.api.dsl.LibraryExtension
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.UnknownConfigurationException
|
||||
import org.gradle.api.artifacts.VersionCatalog
|
||||
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||
import org.gradle.kotlin.dsl.DependencyHandlerScope
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
import org.gradle.kotlin.dsl.findByType
|
||||
|
||||
internal fun Project.findLibs(): VersionCatalog {
|
||||
return extensions.findByType(VersionCatalogsExtension::class.java)!!.named("libs")
|
||||
}
|
||||
|
||||
val Project.isAndroidApp: Boolean
|
||||
get() {
|
||||
return extensions.findByType<ApplicationExtension>() != null
|
||||
}
|
||||
|
||||
val Project.isAndroidLib: Boolean
|
||||
get() {
|
||||
return extensions.findByType<LibraryExtension>() != null
|
||||
}
|
||||
|
||||
val Project.isWebApp: Boolean
|
||||
get() {
|
||||
return hasPlugin("convention-web-app")
|
||||
}
|
||||
|
||||
val Project.isBackendApp: Boolean
|
||||
get() {
|
||||
return hasPlugin("convention-backend-app")
|
||||
}
|
||||
|
||||
internal fun Project.hasAndroidSupport(): Boolean {
|
||||
return isAndroidApp || isAndroidLib
|
||||
}
|
||||
|
||||
internal fun Project.hasMultiplatformSupport(): Boolean = hasPlugin("kotlin-multiplatform")
|
||||
|
||||
private fun Project.hasPlugin(alias: String): Boolean {
|
||||
val plugin = findLibs().findPlugin(alias).get().get().pluginId
|
||||
return pluginManager.hasPlugin(plugin)
|
||||
}
|
||||
|
||||
internal fun DependencyHandlerScope.implementation(deps: Any) {
|
||||
try {
|
||||
add("commonMainImplementation", deps)
|
||||
} catch (_: UnknownConfigurationException) {
|
||||
add("implementation", deps)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun DependencyHandlerScope.androidImplementation(deps: Any) {
|
||||
add("androidMainImplementation", deps)
|
||||
}
|
||||
|
||||
internal fun DependencyHandlerScope.desktopImplementation(deps: Any) {
|
||||
if (BuildFlags.DESKTOP) add("desktopMainImplementation", deps)
|
||||
}
|
||||
|
||||
internal fun Project.applyCoroutines(
|
||||
libs: VersionCatalog,
|
||||
hasAndroid: Boolean = hasAndroidSupport()
|
||||
) {
|
||||
dependencies {
|
||||
implementation(libs.findLibrary("kotlinx-coroutines-core").get())
|
||||
if (hasAndroid) {
|
||||
val lib = libs.findLibrary("kotlinx.coroutines.android").get()
|
||||
if (hasMultiplatformSupport()) {
|
||||
androidImplementation(lib)
|
||||
} else {
|
||||
implementation(lib)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user