Introducing a new way to review your PRs.

Read the announcement

keiyoushi / extensions-source

Source code of extensions in https://github.com/keiyoushi/extensions

View on GitHub

13 documents · Updated Nov 19, 2026

docs / gradle-build-logic

Gradle build logic

Overview

The included Gradle build-logic project lives under gradle/build-logic/** and compiles the repository's convention plugins. gradle/…/settings.gradle.kts creates its own libs and kei version catalogs from gradle/libs.versions.toml and gradle/kei.versions.toml, because this is an included build rather than a normal subproject. gradle/…/build.gradle.kts applies Kotlin/JVM, Kotlin serialization, Spotless, and java-gradle-plugin, then registers five plugin ids from the kei catalog: Android base (AndroidBasePlugin), extension (ExtensionPlugin), library (LibraryPlugin), spotless (SpotlessPlugin), and multisrc theme (ThemePlugin). gradle/build-logic/gradle.properties repeats root Gradle performance settings because Gradle properties are not propagated into included builds.

src/…/AndroidBasePlugin.kt is the shared Android baseline used by the higher-level plugins. It configures Kotlin/Java compatibility through io/…/Kotlin.kt, sets compile/min/target SDKs from the kei catalog, attaches a local proguard-rules.pro as either application or consumer ProGuard rules, disables lint HTML reports, and makes preBuild depend on the Spotless task selected by io/…/Project.kt (spotlessApply locally, spotlessCheck when CI=true). src/…/SpotlessPlugin.kt applies the external Spotless plugin and formats Kotlin, Java, Gradle, and XML inputs; its ktlint version and Kotlin formatting settings are intended to stay in sync with gradle/…/build.gradle.kts.

src/…/ExtensionPlugin.kt is the main convention plugin for extension application modules. It applies Android application, Kotlin serialization, KSP, the Android base plugin, and the Spotless convention. It creates the keiyoushi {} DSL from io/…/KeiyoushiExtension.kt, rewires the Android main source set to module-local src, res, and assets, uses the common manifest and ProGuard files from the root project, configures release signing from signingkey.jks plus KEY_STORE_PASSWORD, ALIAS, and KEY_PASSWORD, and disables APK dependency metadata. It derives the default package suffix from parentProjectName.projectName, validates it with APPLICATION_ID_SUFFIX_REGEX, validates libVersion against VALID_LIB_VERSIONS from io/…/Constant.kt, and computes extension version names as <libVersion>.<versionCode>.

For release variants, ExtensionPlugin.kt wires custom tasks from io/github/keiyoushi/gradle/tasks/**: GenerateManifestTask adds Tachiyomi/TachiyomiX metadata and optional URL deeplink intent filters to a generated manifest; CreateExtensionJarTask collects compiled classes, removes entries already present on the extension library classpath, runs ProGuard with sanitized rules, and packages the merged manifest plus APK res/, assets/, and resources.arsc entries into an unsigned jar; SignExtensionJarTask signs that jar with Android APK Signature Scheme v1 when a keystore is available, otherwise copies it unsigned; ComputeContentHashTask hashes shipped APK and jar contents after normalizing version metadata and R8 map ids; and GenerateSourceInfoTask writes the JSON metadata consumed by publishing/CI to build/keiyoushi-source-info.json. ExtensionPlugin.kt also passes source metadata and the core translations file path into KSP arguments (kei_sources, kei_translations) after evaluation, and makes KSP tasks track the translations JSON as an input.

The extension DSL models live in io/github/keiyoushi/gradle/api/dsl/**. KeiyoushiExtension.kt exposes extension-level fields such as name, versionCode, contentWarning, theme, libVersion, pkgName, deeplinks, and sources. ExtensionSource.kt records source name/language/id/version and accepts either a simple baseUrl = "..." or a structured baseUrl {} block. BaseUrlConfig.kt allows either fixed mirror URLs or a user-editable custom URL; io/…/BaseUrl.kt provides the internal static/mirrors/custom representation and default/all-url behavior. ExtensionDeeplink.kt records host and path-pattern filters, and io/…/Utils.kt centralizes instantiation of deeplink DSL objects. Metadata serialization shapes are in io/…/MetadataModels.kt; these are what ExtensionPlugin.kt encodes for KSP and source-info output.

src/…/ThemePlugin.kt is the convention plugin for lib-multisrc theme libraries. It applies Android library, Kotlin serialization, Android base, and Spotless; creates KeiyoushiThemeExtension.kt; points the main source set at AndroidManifest.xml, src, res, and assets; depends on :core and lint rules; and validates the theme libVersion after evaluation. ExtensionPlugin.kt can consume a theme by evaluating :lib-multisrc:<themeName>, requiring that it applied the multisrc plugin, requiring its libVersion to match the extension, adding its baseVersionCode to the extension versionCode, and merging theme deeplinks with module-local deeplinks.

src/…/LibraryPlugin.kt is the convention plugin for shared Android library modules. It applies Android library, Kotlin serialization, Android base, and Spotless, sets namespace keiyoushi.lib.<project.name>, uses src and assets as source roots, disables Android resources, and adds common compile-only dependencies, Tachiyomi lib v1.6, :core, and :lint-rules. Small Gradle Kotlin DSL helpers under io/github/keiyoushi/gradle/internal/extensions/** keep plugin application, version-catalog access, dependency notation, and CI-aware Spotless task names consistent across these convention plugins.

Coupling

  • If plugin ids or version catalog aliases change, update gradle/…/build.gradle.kts together with all convention-plugin code that calls alias(libs.plugins...) or alias(kei.plugins...) through io/…/PluginManager.kt; these plugins use catalog-generated accessors at compile time, so alias drift breaks the included build before repository modules can configure.
  • If a new Tachiyomi extension library version is added, update all three pieces called out by io/…/Constant.kt: VALID_LIB_VERSIONS, extensionsLib(), and the corresponding version-catalog entry. ExtensionPlugin.kt and ThemePlugin.kt both validate against the list, while dependency resolution uses the mapping function.
  • If generated source processor package/class names change, update GENERATED_EXTENSION_CLASS_FQN in io/…/GenerateManifestTask.kt; the comment says it must match the compiler's generated class constants, and mismatches make generated manifests point Tachiyomi at a non-existent extension class.
  • If source metadata, base-url semantics, or content warning values change, verify ExtensionPlugin.kt, io/…/MetadataModels.kt, io/…/ContentWarning.kt, and io/…/GenerateManifestTask.kt together. The plugin serializes ResolvedSource for KSP, serializes ExtensionMetadata for source-info, and also writes Android manifest metadata; these formats can drift independently.
  • If root formatting rules change, keep gradle/…/build.gradle.kts and src/…/SpotlessPlugin.kt synchronized. The build-logic project formats itself in build.gradle.kts, while repository modules receive formatting from the compiled Spotless convention plugin.
  • If release packaging or reproducibility expectations change, check ExtensionPlugin.kt, CreateExtensionJarTask.kt, SignExtensionJarTask.kt, and ComputeContentHashTask.kt as a single flow. The jar task writes deterministic timestamps and shrinks classes, the signing task may copy unsigned jars when no keystore exists, and the hash task intentionally ignores version/signature noise while still hashing shipped content.

Risks

  • src/…/ExtensionPlugin.kt resolves theme projects with evaluationDependsOn(":lib-multisrc:$themeName") and throws if the target lacks KeiyoushiThemeExtension. If a module's keiyoushi.theme points to a project that was renamed or no longer applies the multisrc plugin, Gradle configuration fails before variants are built.
  • src/…/CreateExtensionJarTask.kt selects the APK with apkDir.get().asFile.walkTopDown().first { it.extension == "apk" }. If Android Gradle Plugin changes the artifact directory layout or produces multiple APK-like files, the extension jar may package resources from the wrong file or fail with no match.
  • src/…/ComputeContentHashTask.kt normalizes R8 map ids and strips manifest version attributes before hashing. If future build tools add new nondeterministic bytes outside VERSION_ATTRIBUTE or MAP_ID, CI content-hash comparisons can report false changes even when shipped behavior is unchanged.

Coverage notes

  • gradle/…/build.gradle.kts, settings.gradle.kts, and gradle.properties: included-build setup, repositories/catalogs, plugin registration, and local build settings.
  • gradle/…/*Plugin.kt: public convention plugins applied by repository modules (AndroidBasePlugin, ExtensionPlugin, LibraryPlugin, SpotlessPlugin, ThemePlugin).
  • gradle/build-logic/src/main/kotlin/io/github/keiyoushi/gradle/api/**: public DSL and enum/value types exposed to module build scripts.
  • gradle/build-logic/src/main/kotlin/io/github/keiyoushi/gradle/internal/**: internal catalog helpers, Kotlin configuration, base-url and metadata models, and supported extension-library version mapping.
  • gradle/build-logic/src/main/kotlin/io/github/keiyoushi/gradle/tasks/**: custom Gradle tasks used by the extension release assembly and metadata flow.