Skip to content

Commit

Permalink
Merge pull request #188 from teogor/feature/ceres-plugin-expansion
Browse files Browse the repository at this point in the history
Introduce Ceres JVM Library and Android Lint Convention Plugins
  • Loading branch information
teogor authored Apr 15, 2024
2 parents 48576bb + 368c4d2 commit 6636ab2
Show file tree
Hide file tree
Showing 18 changed files with 152 additions and 51 deletions.
34 changes: 17 additions & 17 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[versions]
aboutLibraries = "10.8.3"
accompanist = "0.33.2-alpha"
accompanist = "0.34.0"
androidDesugarJdkLibs = "2.0.4"
android-gradle-plugin = "8.2.2"
android-gradle-plugin = "8.3.2"
androidxActivity = "1.8.2"
androidxAnnotation = "1.7.1"
androidxAppCompat = "1.6.1"
androidxBrowser = "1.7.0"
androidxComposeBom = "2024.02.01"
androidxComposeCompiler = "1.5.8"
androidxComposeMaterial3 = "1.2.0"
androidxBrowser = "1.8.0"
androidxComposeBom = "2024.04.00"
androidxComposeCompiler = "1.5.11"
androidxComposeMaterial3 = "1.2.1"
androidxComposeRuntimeTracing = "1.0.0-beta01"
androidxConstraint = "1.1.0-alpha13"
androidxCore = "1.12.0"
Expand All @@ -33,38 +33,38 @@ androidxWindowManager = "1.2.0"
androidxWork = "2.9.0"
apiValidator = "0.14.0"
buildConfig = "3.1.0"
coil = "2.5.0"
coil = "2.6.0"
colorMath = "3.2.0"
dokka = "1.9.10"
espressoCore = "3.5.1"
firebaseBom = "32.7.3"
firebaseBom = "32.8.1"
firebaseCrashlyticsPlugin = "2.9.9"
firebasePerfPlugin = "1.4.2"
gmsPlugin = "4.4.1"
googleMaterial = "1.11.0"
gradlePublish = "1.1.0"
gson = "2.10.1"
hilt = "2.50"
hilt = "2.51.1"
hiltExt = "1.2.0"
jacoco = "0.8.7"
jdom2 = "2.0.6.1"
jsoup = "1.16.1"
junit = "4.13.2"
junit4 = "4.13.2"
kotlin = "1.9.22"
kotlin = "1.9.23"
kotlin-poet = "1.14.2"
kotlin-xml-builder = "1.9.1"
kotlinx-serialization-core = "1.6.2"
kotlinx-serialization-core = "1.6.3"
kotlinxCollections = "0.3.6"
kotlinxCoroutines = "1.7.3"
kotlinxCoroutines = "1.8.0"
kotlinxDatetime = "0.5.0"
kotlinxSerializationJson = "1.6.2"
ksp = "1.9.22-1.0.17"
kotlinxSerializationJson = "1.6.3"
ksp = "1.9.23-1.0.20"
landscapist = "2.3.1"
lifecycleRuntimeKtx = "2.7.0"
lint = "31.2.2"
lint = "31.3.2"
okhttp = "4.12.0"
protobuf = "3.24.4"
protobuf = "3.25.2"
protobufPlugin = "0.9.4"
querent = "1.0.0-alpha02"
retrofit = "2.9.0"
Expand All @@ -83,7 +83,7 @@ google-android-ump = "2.2.0"
about-libraries-core = { group = "com.mikepenz", name = "aboutlibraries-core", version.ref = "aboutLibraries" }
accompanist-testharness = { group = "com.google.accompanist", name = "accompanist-testharness", version.ref = "accompanist" }
accompanist-permissions = { group = "com.google.accompanist", name = "accompanist-permissions", version.ref = "accompanist" }
android-desugarJdkLibs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "androidDesugarJdkLibs" }
android-desugar-jdk-libs = { group = "com.android.tools", name = "desugar_jdk_libs", version.ref = "androidDesugarJdkLibs" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "androidxActivity" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompat" }
androidx-annotation = { group = "androidx.annotation", name = "annotation", version.ref = "androidxAnnotation" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Sep 03 17:17:31 EEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
5 changes: 5 additions & 0 deletions monetisation/messaging/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
android:name="dev.teogor.ceres.monetisation.admob.flag.MANUAL_ADS_SETUP"
android:value="true" />

<property
tools:replace="android:resource"
android:name="android.adservices.AD_SERVICES_CONFIG"
android:resource="@xml/gma_ad_services_config" />

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
Expand Down
12 changes: 12 additions & 0 deletions plugin/library-convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ gradlePlugin {
tags.set(listOf("android", "room", "android-library", "android-development"))
}

register("androidLint") {
id = "dev.teogor.ceres.android.lint"
implementationClass = "AndroidLintConventionPlugin"
displayName = "Android Lint Plugin | Ceres Plugin"
}

register("androidFirebase") {
id = "dev.teogor.ceres.android.application.firebase"
implementationClass = "AndroidApplicationFirebaseConventionPlugin"
Expand Down Expand Up @@ -172,6 +178,12 @@ gradlePlugin {
description = "Streamline Kotlin Library Development with a Standardized Convention"
tags.set(listOf("kotlin", "convention", "build-logic", "library"))
}

register("jvmLibrary") {
id = "dev.teogor.ceres.jvm.library"
implementationClass = "JvmLibraryConventionPlugin"
displayName = "JVM Library Convention"
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import com.android.build.api.dsl.ApplicationExtension
import com.google.firebase.crashlytics.buildtools.gradle.CrashlyticsExtension
import dev.teogor.ceres.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
Expand All @@ -33,7 +34,6 @@ class AndroidApplicationFirebaseConventionPlugin : Plugin<Project> {
apply("com.google.firebase.crashlytics")
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
val bom = libs.findLibrary("firebase-bom").get()
add("implementation", platform(bom))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import dev.teogor.ceres.configureGradleManagedDevices
import dev.teogor.ceres.configureKotlinAndroid
import dev.teogor.ceres.configurePrintApksTask
import dev.teogor.ceres.disableUnnecessaryAndroidTests
import dev.teogor.ceres.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
Expand Down Expand Up @@ -48,7 +49,6 @@ class AndroidLibraryConventionPlugin : Plugin<Project> {
configurePrintApksTask(this)
disableUnnecessaryAndroidTests(target)
}
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
configurations.configureEach {
resolutionStrategy {
val junit4 = libs.findLibrary("junit4")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.api.dsl.LibraryExtension
import com.android.build.api.dsl.Lint
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class AndroidLintConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
when {
pluginManager.hasPlugin(
"com.android.application"
) -> configure<ApplicationExtension> {
lint(Lint::configure)
}

pluginManager.hasPlugin(
"com.android.library"
) -> configure<LibraryExtension> {
lint(Lint::configure)
}

else -> {
pluginManager.apply("com.android.lint")
configure<Lint>(Lint::configure)
}
}
}
}
}

private fun Lint.configure() {
xmlReport = true
checkDependencies = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import com.google.devtools.ksp.gradle.KspExtension
import dev.teogor.ceres.libs
import dev.teogor.ceres.models.RoomOptionsExtension
import dev.teogor.ceres.models.roomCompiler
import dev.teogor.ceres.models.roomKtx
Expand Down Expand Up @@ -54,7 +55,6 @@ class AndroidRoomConventionPlugin : Plugin<Project> {
}
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")
dependencies {
add(
dependencies = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import dev.teogor.ceres.configureKotlinJvm
import org.gradle.api.Plugin
import org.gradle.api.Project

class JvmLibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("org.jetbrains.kotlin.jvm")
apply("dev.teogor.ceres.android.lint")
}
configureKotlinJvm()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal fun ConfigurationContainer.findSpecificDependency(
* @param commonExtension The common extension of the Android project.
*/
internal fun Project.configureAndroidBuildConfig(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val now = Instant.now()
val buildDate = now.atOffset(ZoneOffset.UTC).toLocalDate()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
* Configure Compose-specific options
*/
internal fun Project.configureAndroidCompose(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

commonExtension.apply {
buildFeatures {
compose = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import dev.teogor.ceres.utils.getBooleanProperty
import org.gradle.api.Project

fun Project.configureFlavors(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
flavorConfigurationBlock: ProductFlavor.(flavor: CeresFlavor) -> Unit = {},
) {
val flavoursEnabled = getBooleanProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.gradle.kotlin.dsl.invoke
*/
@Suppress("UnstableApiUsage")
internal fun configureGradleManagedDevices(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {
val pixel4 = DeviceConfig("Pixel 4", 30, "aosp-atd")
val pixel6 = DeviceConfig("Pixel 6", 31, "aosp")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ private fun String.capitalize() = replaceFirstChar {
internal fun Project.configureJacoco(
androidComponentsExtension: AndroidComponentsExtension<*, *, *>,
) {
val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

configure<JacocoPluginExtension> {
libs.findVersion("jacoco").let { jacoco ->
if (jacoco.isPresent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
package dev.teogor.ceres

import com.android.build.api.dsl.CommonExtension
import dev.teogor.ceres.models.desugarJdkLibs
import dev.teogor.ceres.utils.add
import dev.teogor.ceres.utils.getBooleanProperty
import dev.teogor.ceres.utils.getIntProperty
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.dependencies
import org.gradle.kotlin.dsl.getByType
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.kotlin.dsl.withType
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand All @@ -32,9 +34,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
* Configure base Kotlin with Android options
*/
internal fun Project.configureKotlinAndroid(
commonExtension: CommonExtension<*, *, *, *, *>,
commonExtension: CommonExtension<*, *, *, *, *, *>,
) {

commonExtension.apply {
compileSdk = getIntProperty(
key = "ceres.buildfeatures.sdk.compile",
Expand All @@ -53,14 +54,50 @@ internal fun Project.configureKotlinAndroid(
// https://developer.android.com/studio/write/java11-minimal-support-table
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

isCoreLibraryDesugaringEnabled = getBooleanProperty(
key = "ceres.buildfeatures.desugaring.enabled",
defaultValue = true,
)
}
}

configureKotlin()

dependencies {
if (getBooleanProperty(
key = "ceres.buildfeatures.desugaring.enabled",
defaultValue = true,
)
) {
add(
dependencies = listOf(
desugarJdkLibs,
),
logger = logger,
libs = libs,
)
}
}
}

/**
* Configure base Kotlin options for JVM (non-Android)
*/
internal fun Project.configureKotlinJvm() {
extensions.configure<JavaPluginExtension> {
// Up to Java 11 APIs are available through desugaring
// https://developer.android.com/studio/write/java11-minimal-support-table
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

configureKotlin()
}

/**
* Configure base Kotlin options
*/
private fun Project.configureKotlin() {
// Use withType to workaround https://youtrack.jetbrains.com/issue/KT-55947
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
Expand All @@ -71,26 +108,9 @@ internal fun Project.configureKotlinAndroid(
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",
)
}
}

val libs = extensions.getByType<VersionCatalogsExtension>().named("libs")

dependencies {
if (getBooleanProperty(
key = "ceres.buildfeatures.desugaring.enabled",
defaultValue = true,
)
) {
val desugarJdkLibs = libs.findLibrary("android.desugarJdkLibs")
if (desugarJdkLibs.isPresent) {
add("coreLibraryDesugaring", desugarJdkLibs.get())
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.teogor.ceres

import org.gradle.api.Project
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.getByType

val Project.libs
get(): VersionCatalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ enum class DependencyType(val gradleNotation: String) {
ANDROID_TEST_IMPLEMENTATION("androidTestImplementation"),
TEST_IMPLEMENTATION("testImplementation"),
COMPILE_ONLY("compileOnly"),
CORE_LIBRARY_DESUGARING("coreLibraryDesugaring"),
}
Loading

0 comments on commit 6636ab2

Please sign in to comment.