-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
build: Introduce Gradle Convention Plugins #20778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
david-allison
wants to merge
8
commits into
ankidroid:main
Choose a base branch
from
david-allison:convention-plugin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
38486eb
build: Introduce Android Gradle Convention Plugin
david-allison 1576c75
build: apply lint to all android libraries
david-allison aafd06d
build: move unused proguard 'consumer-rules'
david-allison b5db52b
refactor(build): remove default test runner
david-allison 216fffa
build(libs): remove minification & proguard
david-allison d54d515
build: apply JaCoCo to all android libraries
david-allison 9761418
build: Introduce Kotlin Gradle Convention Plugin
david-allison 1ff616b
build: Introduce API Gradle Convention Plugin
david-allison File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /* | ||
| * Copyright (c) 2026 David Allison <davidallisongithub@gmail.com> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU General Public License as published by the Free Software | ||
| * Foundation; either version 3 of the License, or (at your option) any later | ||
| * version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| // Convention plugin: Android library published as a public API artifact. | ||
| // | ||
| // Distinct from ankidroid.android-library: | ||
| // * Java source/target compat is 11 (not 17) for consumer compatibility. | ||
| // * Kotlin explicit-API strict mode is enabled (library-author quality check). | ||
| // * minSdk is not set. | ||
| // | ||
| // Publishing (maven-publish, singleVariant setup, POM metadata) is left to | ||
| // the consuming module — it's intrinsically per-module configuration. | ||
|
|
||
| import com.android.build.api.dsl.LibraryExtension | ||
| import com.ichi2.anki.gradle.libsVersionFor | ||
| import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension | ||
|
|
||
| plugins { | ||
| id("com.android.library") | ||
| } | ||
|
|
||
| extensions.configure<LibraryExtension> { | ||
| compileSdk = libsVersionFor("compileSdk").toInt() | ||
|
|
||
| compileOptions { | ||
| // API remains on VERSION_11 for consumer compatibility. | ||
| sourceCompatibility = JavaVersion.VERSION_11 | ||
| targetCompatibility = JavaVersion.VERSION_11 | ||
| } | ||
| } | ||
|
|
||
| extensions.configure<KotlinAndroidProjectExtension> { | ||
| explicitApi() | ||
| compilerOptions { | ||
| // Stricter checks on public API shape for library authors. | ||
| // See https://kotlinlang.org/docs/whatsnew14.html#explicit-api-mode-for-library-authors | ||
| freeCompilerArgs.add("-Xexplicit-api=strict") | ||
| } | ||
| } | ||
|
|
||
| // Shared project-wide lint configuration. | ||
| apply(from = "${rootDir}/lint.gradle") |
49 changes: 49 additions & 0 deletions
49
buildSrc/src/main/kotlin/ankidroid.android.library.gradle.kts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright (c) 2026 David Allison <davidallisongithub@gmail.com> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU General Public License as published by the Free Software | ||
| * Foundation; either version 3 of the License, or (at your option) any later | ||
| * version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| /* | ||
| Convention plugin: applies `com.android.library` and pins the settings | ||
| shared across every Android library module in this project. | ||
|
|
||
| This does not apply to the API module, | ||
| */ | ||
|
|
||
| import com.android.build.api.dsl.LibraryExtension | ||
| import com.ichi2.anki.gradle.libsVersionFor | ||
|
|
||
| plugins { | ||
| id("com.android.library") | ||
| } | ||
|
|
||
| extensions.configure<LibraryExtension> { | ||
| compileSdk = libsVersionFor("compileSdk").toInt() | ||
|
|
||
| defaultConfig { | ||
| minSdk = libsVersionFor("minSdk").toInt() | ||
| } | ||
|
|
||
| compileOptions { | ||
| sourceCompatibility = JavaVersion.VERSION_17 | ||
| targetCompatibility = JavaVersion.VERSION_17 | ||
| } | ||
| } | ||
|
|
||
| // Shared project-wide lint configuration. | ||
| apply(from = "${rootDir}/lint.gradle") | ||
|
|
||
| // Apply jacoco so module unit tests produce .exec files that | ||
| // AnkiDroid's jacocoUnitTestReport aggregates across modules. | ||
| apply(from = "${rootDir}/jacocoSupport.gradle") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright (c) 2026 David Allison <davidallisongithub@gmail.com> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU General Public License as published by the Free Software | ||
| * Foundation; either version 3 of the License, or (at your option) any later | ||
| * version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| // Convention plugin: applies the Kotlin JVM plugin and pins Java/Kotlin | ||
| // toolchain settings for pure-JVM (non-Android) modules in this project. | ||
|
|
||
| import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
|
||
| plugins { | ||
| id("org.jetbrains.kotlin.jvm") | ||
| } | ||
|
|
||
| tasks.withType(JavaCompile::class).configureEach { | ||
| sourceCompatibility = JavaVersion.VERSION_17.toString() | ||
| targetCompatibility = JavaVersion.VERSION_17.toString() | ||
| } | ||
|
|
||
| tasks.withType(KotlinCompile::class).configureEach { | ||
| compilerOptions { | ||
| jvmTarget = JvmTarget.JVM_17 | ||
| } | ||
| } |
38 changes: 38 additions & 0 deletions
38
buildSrc/src/main/kotlin/com/ichi2/anki/gradle/VersionCatalogs.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| * Copyright (c) 2026 David Allison <davidallisongithub@gmail.com> | ||
| * | ||
| * This program is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU General Public License as published by the Free Software | ||
| * Foundation; either version 3 of the License, or (at your option) any later | ||
| * version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | ||
| * PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU General Public License along with | ||
| * this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package com.ichi2.anki.gradle | ||
|
|
||
| import org.gradle.api.Project | ||
| import org.gradle.api.artifacts.VersionCatalog | ||
| import org.gradle.api.artifacts.VersionCatalogsExtension | ||
| import org.gradle.kotlin.dsl.getByType | ||
|
|
||
| // Type-safe `libs` accessors aren't available in precompiled script plugins, | ||
| // so read versions from the `libs` catalog explicitly. | ||
|
|
||
| @Volatile | ||
| private var cachedLibs: VersionCatalog? = null | ||
|
|
||
| // A Project reference is required, so this can't be `by lazy { }` | ||
| private fun Project.libs(): VersionCatalog = | ||
| cachedLibs ?: extensions | ||
| .getByType<VersionCatalogsExtension>() | ||
| .named("libs") | ||
| .also { cachedLibs = it } | ||
|
|
||
| fun Project.libsVersionFor(alias: String): String = | ||
| libs().findVersion(alias).get().requiredVersion |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +0,0 @@ | ||
| # Add project specific ProGuard rules here. | ||
| # You can control the set of applied configuration files using the | ||
| # proguardFiles setting in build.gradle. | ||
| # | ||
| # For more details, see | ||
| # http://developer.android.com/guide/developing/tools/proguard.html | ||
|
|
||
| # If your project uses WebView with JS, uncomment the following | ||
| # and specify the fully qualified class name to the JavaScript interface | ||
| # class: | ||
| #-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
| # public *; | ||
| #} | ||
|
|
||
| # Uncomment this to preserve the line number information for | ||
| # debugging stack traces. | ||
| #-keepattributes SourceFile,LineNumberTable | ||
|
|
||
| # If you keep the line number information, uncomment this to | ||
| # hide the original source file name. | ||
| #-renamesourcefileattribute SourceFile | ||
|
|
||
| # FIXME remove this entire Android 4.2 workaround from 12/3/15 timrae commit for 2.15.x+ | ||
| # Samsung Android 4.2 bug workaround | ||
| # https://code.google.com/p/android/issues/detail?id=78377 | ||
| -keepattributes ** | ||
| -keep class !android.support.v7.view.menu.**,!android.support.design.internal.NavigationMenu,!android.support.design.internal.NavigationMenuPresenter,!android.support.design.internal.NavigationSubMenu,** {*;} | ||
| #5806 - Class: ActionBarOverflow | ||
| -keep public class android.support.v7.internal.view.menu.** { *; } | ||
| -keep public class androidx.appcompat.view.menu.** { *; } | ||
| -dontpreverify | ||
| -dontoptimize | ||
| -dontshrink | ||
| -dontwarn ** | ||
| -dontnote ** | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.