|
| 1 | +/* |
| 2 | + * Copyright (c) 2026 David Allison <davidallisongithub@gmail.com> |
| 3 | + * |
| 4 | + * This program is free software; you can redistribute it and/or modify it under |
| 5 | + * the terms of the GNU General Public License as published by the Free Software |
| 6 | + * Foundation; either version 3 of the License, or (at your option) any later |
| 7 | + * version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, but WITHOUT ANY |
| 10 | + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 11 | + * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 12 | + * |
| 13 | + * You should have received a copy of the GNU General Public License along with |
| 14 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | + */ |
| 16 | + |
| 17 | +// Convention plugin: Android library published as a public API artifact. |
| 18 | +// |
| 19 | +// Distinct from ankidroid.android-library: |
| 20 | +// * Java source/target compat is 11 (not 17) for consumer compatibility. |
| 21 | +// * Kotlin explicit-API strict mode is enabled (library-author quality check). |
| 22 | +// * minSdk is not set. |
| 23 | +// |
| 24 | +// Publishing (maven-publish, singleVariant setup, POM metadata) is left to |
| 25 | +// the consuming module — it's intrinsically per-module configuration. |
| 26 | + |
| 27 | +import com.android.build.api.dsl.LibraryExtension |
| 28 | +import org.gradle.api.artifacts.VersionCatalogsExtension |
| 29 | +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension |
| 30 | + |
| 31 | +plugins { |
| 32 | + id("com.android.library") |
| 33 | +} |
| 34 | + |
| 35 | +val libs = extensions.getByType<VersionCatalogsExtension>().named("libs") |
| 36 | +fun versionInt(alias: String): Int = |
| 37 | + libs.findVersion(alias).get().requiredVersion.toInt() |
| 38 | + |
| 39 | +extensions.configure<LibraryExtension> { |
| 40 | + compileSdk = versionInt("compileSdk") |
| 41 | + |
| 42 | + compileOptions { |
| 43 | + // API remains on VERSION_11 for consumer compatibility. |
| 44 | + sourceCompatibility = JavaVersion.VERSION_11 |
| 45 | + targetCompatibility = JavaVersion.VERSION_11 |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +extensions.configure<KotlinAndroidProjectExtension> { |
| 50 | + explicitApi() |
| 51 | + compilerOptions { |
| 52 | + // Stricter checks on public API shape for library authors. |
| 53 | + // See https://kotlinlang.org/docs/whatsnew14.html#explicit-api-mode-for-library-authors |
| 54 | + freeCompilerArgs.add("-Xexplicit-api=strict") |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +// Shared project-wide lint configuration. |
| 59 | +apply(from = "${rootDir}/lint.gradle") |
0 commit comments