的
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/build
|
||||
@@ -0,0 +1,54 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
group = "ycharts.android.buildlogic"
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
google()
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly(versionCatalogLibs.android.gradle.plugin)
|
||||
compileOnly(versionCatalogLibs.kotlin.gradle.plugin)
|
||||
}
|
||||
|
||||
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
}
|
||||
}
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
register("androidApplication") {
|
||||
id = "ycharts.android.application"
|
||||
implementationClass = "conventions.ApplicationConventionPlugin"
|
||||
}
|
||||
|
||||
register("androidApplicationCompose") {
|
||||
id = "ycharts.android.application.compose"
|
||||
implementationClass = "conventions.ComposeApplicationConventionPlugin"
|
||||
}
|
||||
|
||||
register("androidLibraryCompose") {
|
||||
id = "ycharts.android.library.compose"
|
||||
implementationClass = "conventions.LibraryComposeConventionPlugin"
|
||||
}
|
||||
|
||||
register("androidLibrary") {
|
||||
id = "ycharts.android.library"
|
||||
implementationClass = "conventions.LibraryConventionPlugin"
|
||||
}
|
||||
|
||||
register("androidTest") {
|
||||
id = "ycharts.android.test"
|
||||
implementationClass = "conventions.AndroidTestConventionPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
versionCatalogs {
|
||||
create("versionCatalogLibs") {
|
||||
from(files("../gradle/libs.versions.toml"))
|
||||
}
|
||||
}
|
||||
}
|
||||
rootProject.name = "build-logic"
|
||||
@@ -0,0 +1,31 @@
|
||||
package conventions
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import org.gradle.kotlin.dsl.kotlin
|
||||
|
||||
/**
|
||||
* Android test convention plugin
|
||||
*
|
||||
* @constructor Create empty Android test convention plugin
|
||||
*/
|
||||
class AndroidTestConventionPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
val libs = extensions.getByType<VersionCatalogsExtension>().named("versionCatalogLibs")
|
||||
dependencies {
|
||||
add("testImplementation", libs.findBundle("test").get())
|
||||
add("testImplementation", libs.findBundle("mock").get())
|
||||
add("testImplementation", libs.findBundle("coroutine.test").get())
|
||||
add("testImplementation", libs.findLibrary("androidx.junit").get())
|
||||
add("androidTestImplementation", kotlin("test"))
|
||||
add("testImplementation", kotlin("test"))
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package conventions
|
||||
|
||||
import com.android.build.api.dsl.ApplicationExtension
|
||||
import com.android.build.api.dsl.Packaging
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import ycharts.android.configureKotlinAndroid
|
||||
|
||||
/**
|
||||
* Application convention plugin
|
||||
*
|
||||
* @constructor Create empty Application convention plugin
|
||||
*/
|
||||
class ApplicationConventionPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
val libs = extensions.getByType<VersionCatalogsExtension>().named("versionCatalogLibs")
|
||||
with(pluginManager) {
|
||||
apply(libs.findPlugin("android.application").get().get().pluginId)
|
||||
apply(libs.findPlugin("kotlin.android").get().get().pluginId)
|
||||
}
|
||||
extensions.configure<ApplicationExtension> {
|
||||
configureKotlinAndroid(this)
|
||||
fun Packaging.() {
|
||||
resources {
|
||||
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||||
excludes += "META-INF/DEPENDENCIES"
|
||||
excludes += "META-INF/gradle/*"
|
||||
}
|
||||
}
|
||||
defaultConfig.targetSdk = 33
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package conventions
|
||||
|
||||
import com.android.build.api.dsl.ApplicationExtension
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import ycharts.android.configureComposeApplication
|
||||
|
||||
|
||||
/**
|
||||
* Compose application convention plugin
|
||||
*
|
||||
* @constructor Create empty Compose application convention plugin
|
||||
*/
|
||||
class ComposeApplicationConventionPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
val libs = extensions.getByType<VersionCatalogsExtension>().named("versionCatalogLibs")
|
||||
pluginManager.apply(libs.findPlugin("android.application").get().get().pluginId)
|
||||
val extension = extensions.getByType<ApplicationExtension>()
|
||||
configureComposeApplication(extension)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package conventions
|
||||
|
||||
import com.android.build.gradle.LibraryExtension
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import ycharts.android.configureComposeApplication
|
||||
|
||||
/**
|
||||
* Library compose convention plugin
|
||||
*
|
||||
* @constructor Create empty Library compose convention plugin
|
||||
*/
|
||||
class LibraryComposeConventionPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
val libs = extensions.getByType<VersionCatalogsExtension>().named("versionCatalogLibs")
|
||||
pluginManager.apply(libs.findPlugin("android.library").get().get().pluginId)
|
||||
val extension = extensions.getByType<LibraryExtension>()
|
||||
configureComposeApplication(extension)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package conventions
|
||||
|
||||
import com.android.build.gradle.LibraryExtension
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||
import org.gradle.kotlin.dsl.configure
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import org.gradle.kotlin.dsl.kotlin
|
||||
import ycharts.android.configureKotlinAndroid
|
||||
|
||||
/**
|
||||
* Library convention plugin
|
||||
*
|
||||
* @constructor Create empty Library convention plugin
|
||||
*/
|
||||
class LibraryConventionPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
with(target) {
|
||||
val libs = extensions.getByType<VersionCatalogsExtension>().named("versionCatalogLibs")
|
||||
with(pluginManager) {
|
||||
apply(libs.findPlugin("android.library").get().get().pluginId)
|
||||
apply(libs.findPlugin("kotlin.android").get().get().pluginId)
|
||||
}
|
||||
|
||||
extensions.configure<LibraryExtension> {
|
||||
configureKotlinAndroid(this)
|
||||
defaultConfig.targetSdk = 33
|
||||
}
|
||||
|
||||
dependencies {
|
||||
add("implementation", libs.findLibrary("coroutine").get())
|
||||
add("testImplementation", kotlin("test"))
|
||||
add("testImplementation", libs.findBundle("coroutine.test").get())
|
||||
add("testImplementation", libs.findLibrary("androidx.junit").get())
|
||||
add("androidTestImplementation", libs.findLibrary("androidx.junit").get())
|
||||
add("androidTestImplementation", kotlin("test"))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package ycharts.android
|
||||
|
||||
/**
|
||||
* This is shared between :app and :benchmarks module to provide configurations type safety.
|
||||
*/
|
||||
@Suppress("unused")
|
||||
enum class AppBuildType(val applicationIdSuffix: String? = null) {
|
||||
DEBUG(".debug"),
|
||||
RELEASE
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package ycharts.android
|
||||
|
||||
import com.android.build.api.dsl.CommonExtension
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.artifacts.VersionCatalogsExtension
|
||||
import org.gradle.kotlin.dsl.dependencies
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
|
||||
|
||||
/**
|
||||
* Configure compose application
|
||||
*
|
||||
* @param commonExtension
|
||||
*/
|
||||
internal fun Project.configureComposeApplication(
|
||||
commonExtension: CommonExtension<*, *, *, *>,
|
||||
) {
|
||||
val libs = extensions.getByType<VersionCatalogsExtension>().named("versionCatalogLibs")
|
||||
|
||||
commonExtension.apply {
|
||||
buildFeatures {
|
||||
compose = true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion =
|
||||
libs.findVersion("androidxComposeCompiler").get().toString()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
val bom = libs.findLibrary("androidx-compose-bom").get()
|
||||
add("implementation", platform(bom))
|
||||
add("implementation", libs.findBundle("compose").get())
|
||||
add("androidTestImplementation", platform(bom))
|
||||
add("androidTestImplementation", libs.findLibrary("androidx.compose.ui.test").get())
|
||||
add("debugImplementation",libs.findLibrary("androidx.compose.ui-manifest-test").get())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package ycharts.android
|
||||
|
||||
import com.android.build.api.dsl.CommonExtension
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.provideDelegate
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
/**
|
||||
* Configure base Kotlin with Android options
|
||||
*/
|
||||
internal fun Project.configureKotlinAndroid(
|
||||
commonExtension: CommonExtension<*, *, *, *>,
|
||||
) {
|
||||
commonExtension.apply {
|
||||
compileSdk = 33
|
||||
packagingOptions {
|
||||
resources {
|
||||
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||||
excludes += "META-INF/DEPENDENCIES"
|
||||
excludes += "META-INF/gradle/*"
|
||||
excludes += "META-INF/LICENSE.*"
|
||||
excludes += "META-INF/LICENSE-notice.md"
|
||||
}
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 26
|
||||
testHandleProfiling = true
|
||||
testFunctionalTest = true
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
// Use withType to workaround https://youtrack.jetbrains.com/issue/KT-55947
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
// Set JVM target to 17
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
// Treat all Kotlin warnings as errors (disabled by default)
|
||||
// Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties
|
||||
val warningsAsErrors: String? by project
|
||||
allWarningsAsErrors = warningsAsErrors.toBoolean()
|
||||
freeCompilerArgs = freeCompilerArgs + listOf(
|
||||
"-opt-in=kotlin.RequiresOptIn",
|
||||
// Enable experimental coroutines APIs, including Flow
|
||||
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
|
||||
"-opt-in=kotlinx.coroutines.FlowPreview",
|
||||
"-opt-in=kotlin.Experimental",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user