<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by AlirezaPK on Medium]]></title>
        <description><![CDATA[Stories by AlirezaPK on Medium]]></description>
        <link>https://medium.com/@AlirezaPK?source=rss-10c266687d0e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*VrkWbahjeM_eiZci7fjpUQ.jpeg</url>
            <title>Stories by AlirezaPK on Medium</title>
            <link>https://medium.com/@AlirezaPK?source=rss-10c266687d0e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:49:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@AlirezaPK/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Step by Step guide to Gradle Convention Plugin]]></title>
            <link>https://medium.com/@AlirezaPK/step-by-step-guide-to-gradle-convention-plugin-798ee02f4c51?source=rss-10c266687d0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/798ee02f4c51</guid>
            <category><![CDATA[modularization]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[multi-module]]></category>
            <dc:creator><![CDATA[AlirezaPK]]></dc:creator>
            <pubDate>Tue, 21 Jul 2026 18:47:31 GMT</pubDate>
            <atom:updated>2026-07-23T14:08:26.848Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cOb5Cesqms0xhffRucYFwg.png" /></figure><p>In a multi-module Android project, repeating the same build configurations (like <em>compileSdk</em>, <em>minSdk</em>, Compose dependencies, or linting rules) in every module’s <em>build.gradle.kts</em> quickly leads to boilerplate, inconsistencies, and maintenance nightmares.</p><p><strong>Convention Plugins</strong> solve this elegantly. They allow you to extract shared build logic into a dedicated, reusable module, ensuring your architecture remains consistent.</p><p>This guide walks you through creating a <em>build-logic</em> and writing custom convention plugins for Android Libraries, Jetpack Compose, Koin, Detekt, and finally, an aggregated Feature plugin.</p><h3>The Final Project Structure</h3><p>Before diving into the steps, here is the complete project structure tree reflecting the files and directories we will create:</p><pre>root-project/<br>├── build-logic/<br>│   ├── convention/<br>│   │   ├── src/<br>│   │   │   └── main/<br>│   │   │       └── kotlin/<br>│   │   │           ├── AndroidFeatureConventionPlugin.kt<br>│   │   │           ├── AndroidComposeConventionPlugin.kt<br>│   │   │           ├── AndroidLibraryConventionPlugin.kt<br>│   │   │           ├── DetektConventionPlugin.kt<br>│   │   │           ├── KoinConventionPlugin.kt<br>│   │   │           └── com/<br>│   │   │               └── conventionplayground/<br>│   │   │                   └── convention/<br>│   │   │                       ├── AndroidCompose.kt<br>│   │   │                       ├── Detekt.kt<br>│   │   │                       ├── KotlinAndroid.kt<br>│   │   │                       └── ProjectExtension.kt<br>│   │   └── build.gradle.kts<br>│   └── settings.gradle.kts<br>├── config/<br>│   └── detekt.yml<br>├── gradle/<br>│   └── libs.versions.toml<br>├── settings.gradle.kts<br>└── build.gradle.kts</pre><h3>Part 1: Setting Up the build-logic Foundation</h3><h4>Step 1: Isolate the Build Logic</h4><p>Create a <em>build-logic</em> directory in the root of your project.<br>This directory will act as an included build. By isolating our convention plugins in a separate build, we prevent them from slowing down the configuration phase of our main application modules, keeping build logic cleanly separated from business logic.</p><h4>Step 2: Include the Build in Root Settings</h4><p>Add includeBuild(“build-logic”) to your root <em>settings.gradle.kts</em> and sync Gradle:</p><pre>// root settings.gradle.kts<br>includeBuild(&quot;build-logic&quot;)</pre><p>This tells the root Gradle build to recognize `build-logic` as an independent, composite build. Syncing is required so the IDE registers the new build structure.</p><h4>Step 3: Create the Convention Module Directory</h4><p>Create a <em>convention </em>directory inside the <em>build-logic</em> directory.<br>This directory will serve as the actual Gradle subproject that houses our convention plugin and build configuration.</p><h4>Step 4: Configure `build-logic` Settings</h4><p>Create <em>settings.gradle.kts</em> inside the <em>build-logic</em> directory, add the following code, and sync Gradle:</p><pre>// build-logic/settings.gradle.kts<br>pluginManagement {<br>    repositories {<br>        gradlePluginPortal()<br>        google()<br>    }<br>}<br><br>dependencyResolutionManagement {<br>    repositories {<br>        google {<br>            content {<br>                includeGroupByRegex(&quot;com\\.android.*&quot;)<br>                includeGroupByRegex(&quot;com\\.google.*&quot;)<br>                includeGroupByRegex(&quot;androidx.*&quot;)<br>            }<br>        }<br>        mavenCentral()<br>    }<br>    versionCatalogs {<br>        create(&quot;libs&quot;) {<br>            from(files(&quot;../gradle/libs.versions.toml&quot;))<br>        }<br>    }<br>}<br><br>rootProject.name = &quot;build-logic&quot;<br>include(&quot;:convention&quot;)</pre><p><em>pluginManagement</em> and <em>dependencyResolutionManagement </em>define where Gradle should look for plugins and dependencies for this specific included build. Crucially, <em>versionCatalogs </em>imports your root project’s <em>libs.versions.toml</em> file. This allows your convention plugins to use the exact same centralized dependency versions as your app modules.</p><h4>Step 5: Initialize the Convention Build File</h4><p>Create <em>build.gradle.kts</em> inside the <em>convention</em> directory, add the following code, and sync Gradle:</p><pre>// build-logic/convention/build.gradle.kts<br>plugins {<br>    `kotlin-dsl`<br>}<br><br>group = &quot;com.conventionplayground.buildlogic&quot;</pre><p>The <em>kotlin-dsl</em> plugin is mandatory for writing Gradle plugins in Kotlin, providing the necessary Gradle API and Kotlin extensions. The <em>group</em> sets the namespace for the compiled plugin classes.</p><h4>Step 6: Add Android Gradle Plugin to Version Catalog</h4><p>Add the following line to your root <em>gradle/libs.versions.toml</em> file (under the <em>[libraries]</em> section):</p><pre># gradle/libs.versions.toml<br>android-gradlePlugin = { group = &quot;com.android.tools.build&quot;, name = &quot;gradle&quot;, version.ref = &quot;agp&quot; }</pre><p>We need to add the Android Gradle Plugin (AGP) to our version catalog so that our convention module can depend on it. This allows us to access Android-specific Gradle extensions (like <em>LibraryExtension</em>) in our Kotlin code.</p><h4>Step 7: Configure Java and Dependencies for Convention</h4><p>Add the following to <em>build-logic/convention/build.gradle.kts</em> and sync Gradle:</p><pre>// build-logic/convention/build.gradle.kts<br>java {<br>    sourceCompatibility = JavaVersion.VERSION_17<br>    targetCompatibility = JavaVersion.VERSION_17<br>}<br><br>dependencies {<br>    compileOnly(libs.android.gradlePlugin)<br>}</pre><p>Modern versions of AGP require Java 17 to compile, so we set the Java compatibility for the convention module. We add <em>libs.android.gradlePlugin</em> as a <em>compileOnly </em>dependency because the convention module needs the AGP classes to compile our plugin code, but the actual AGP will be provided by the consuming app/library modules at runtime.</p><h4>Step 8: Create a Version Catalog Extension</h4><p>Create <em>ProjectExtension.kt</em> inside <em>build-logic/convention/src/main/kotlin/com/conventionplayground/convention:</em></p><pre>// build-logic/convention/src/main/kotlin/com/conventionplayground/convention/ProjectExtension.kt<br>val Project.libs<br>    get(): VersionCatalog = extensions.getByType&lt;VersionCatalogsExtension&gt;().named(&quot;libs&quot;)</pre><p>This creates a convenient Kotlin extension property on the <em>Project</em> object. Instead of writing verbose code to fetch the version catalog every time we need a dependency, we can simply call <em>libs</em> in our convention plugins.</p><h4>Step 9: Create Compose Convention Plugin and Helper</h4><p>Create <em>AndroidComposeConventionPlugin.kt</em> inside <em>build-logic/convention/src/main/kotlin:</em></p><pre>// build-logic/convention/src/main/kotlin/AndroidComposeConventionPlugin.kt <br>class AndroidComposeConventionPlugin : Plugin&lt;Project&gt; {<br>    override fun apply(target: Project) {<br>        with(target) {<br>            with(pluginManager) {<br>                apply(&quot;com.android.library&quot;)<br>                apply(&quot;org.jetbrains.kotlin.plugin.compose&quot;)<br>            }<br><br>            extensions.configure&lt;LibraryExtension&gt; {<br>                configureAndroidCompose(this)<br>            }<br>        }<br>    }<br>}</pre><p>Create <em>AndroidCompose.kt</em> inside <em>build-logic/convention/src/main/kotlin/com/conventionplayground/convention:</em></p><pre>// build-logic/convention/src/main/kotlin/com/conventionplayground/convention/AndroidCompose.kt<br>internal fun Project.configureAndroidCompose(<br>    commonExtension: CommonExtension<br>) {<br>    commonExtension.apply {<br>        buildFeatures.apply {<br>            compose = true<br>        }<br><br>        dependencies {<br>            val bom = libs.findLibrary(&quot;androidx-compose-bom&quot;).get()<br>            add(&quot;implementation&quot;, platform(bom))<br>            add(&quot;implementation&quot;, libs.findLibrary(&quot;androidx-compose-ui&quot;).get())<br>            add(&quot;implementation&quot;, libs.findLibrary(&quot;androidx-compose-ui-graphics&quot;).get())<br>            add(&quot;implementation&quot;, libs.findLibrary(&quot;androidx-compose-material3&quot;).get())<br>            add(&quot;implementation&quot;, libs.findLibrary(&quot;androidx-compose-ui-tooling-preview&quot;).get())<br>            add(&quot;debugImplementation&quot;, libs.findLibrary(&quot;androidx-compose-ui-tooling&quot;).get())<br>        }<br>    }<br>}</pre><p>The Plugin class applies the base Android Library plugin and the Kotlin Compose compiler plugin. It then configures the <em>LibraryExtension</em> using our helper function. The helper function enables the Compose build feature and injects all standard Compose dependencies using the <em>libs </em>extension we created in Step 8, ensuring every module gets the exact same setup.</p><h4>Step 10: Create Base Library Convention Plugin and Helper</h4><p>Create <em>AndroidLibraryConventionPlugin.kt</em> inside <em>build-logic/convention/src/main/kotlin:</em></p><pre>// build-logic/convention/src/main/kotlin/AndroidLibraryConventionPlugin.kt<br>class AndroidLibraryConventionPlugin : Plugin&lt;Project&gt; {<br>    override fun apply(target: Project) {<br>        with(target) {<br>            with(pluginManager) {<br>                apply(&quot;com.android.library&quot;)<br>            }<br><br>            extensions.configure&lt;LibraryExtension&gt; {<br>                configureKotlinAndroid(this)<br>            }<br>        }<br>    }<br>}</pre><p>Create <em>KotlinAndroid.kt</em> inside <em>build-logic/convention/src/main/kotlin/com/conventionplayground/convention:</em></p><pre>// build-logic/convention/src/main/kotlin/com/conventionplayground/convention/KotlinAndroid.kt<br>internal fun Project.configureKotlinAndroid(<br>    commonExtension: CommonExtension<br>) {<br>    commonExtension.apply {<br>        compileSdk = 37<br><br>        defaultConfig.apply {<br>            minSdk = 29<br>        }<br><br>        compileOptions.apply {<br>            sourceCompatibility = JavaVersion.VERSION_11<br>            targetCompatibility = JavaVersion.VERSION_11<br>        }<br>    }<br>}</pre><p>This plugin acts as the base configuration for any Android Library module. The helper function standardizes the <em>compileSdk</em>, <em>minSdk</em>, and Java compile options across all modules.</p><h4>Step 11: Register Plugin IDs in Version Catalog</h4><p>Add the following to your root <em>gradle/libs.versions.toml</em> file (under the <em>[plugins]</em> section):</p><pre># gradle/libs.versions.toml<br>convention-android-library = { id = &quot;convention.android.library&quot; }<br>convention-compose = { id = &quot;convention.compose&quot; }</pre><p>We define the custom plugin IDs here. By putting them in the version catalog, we can use the clean <em>alias(libs.plugins…)</em> syntax in our app modules instead of hardcoding string IDs.</p><h4>Step 12: Map Plugin IDs to Implementation Classes</h4><p>Add the following to <em>build-logic/convention/build.gradle.kts:</em></p><pre>// build-logic/convention/build.gradle.kts<br>gradlePlugin {<br>    plugins {<br>        register(&quot;androidLibrary&quot;) {<br>            id = libs.plugins.convention.android.library.get().pluginId<br>            implementationClass = &quot;AndroidLibraryConventionPlugin&quot;<br>        }<br><br>        register(&quot;androidCompose&quot;) {<br>            id = libs.plugins.convention.compose.get().pluginId<br>            implementationClass = &quot;AndroidComposeConventionPlugin&quot;<br>        }<br>    }<br>}</pre><p>This is the final wiring step for the convention module. The <em>gradlePlugin </em>block registers our custom plugins, mapping the plugin IDs defined in the TOML file to the actual Kotlin classes we wrote in Steps 9 and 10.</p><h4>Step 13: Apply Convention Plugins in Target Modules</h4><p>In any feature or core module’s <em>build.gradle.kts</em>, apply the newly created convention plugins:</p><pre>// app/feature-module/build.gradle.kts<br>plugins {<br>    alias(libs.plugins.convention.android.library)<br>    alias(libs.plugins.convention.compose)<br>}</pre><p>This is the ultimate goal of the setup. By applying these two lines, the target module automatically inherits all the Android base configurations and Jetpack Compose configurations. This keeps your module <em>build.gradle.kts</em> files incredibly clean and ensures strict consistency.</p><h3>Part 2: Extending with Third-Party Libraries</h3><p>Now that the base Android and Compose conventions are set up, we can extend our <em>build-logic</em> to handle third-party libraries, ensuring dependency injection setup is uniform across all modules.</p><h4>Koin</h4><p>To ensure dependency injection is set up uniformly across your architecture, we can create a convention plugin for Koin. This automatically applies the Koin compiler plugin and injects the necessary core and annotation dependencies, keeping your DI configuration consistent and your module build files clean.</p><h4>Step 14: Add Koin Dependencies and Plugin to Version Catalog &amp; Root Build</h4><p>Add the Koin versions, libraries, and compiler plugin to your root <em>gradle/libs.versions.toml</em> file. Then, add the plugin to your root <em>build.gradle.kts:</em></p><pre># gradle/libs.versions.toml<br>[versions]<br>koin = &quot;4.2.2&quot;<br>koin-plugin = &quot;1.0.2&quot;<br><br>[libraries]<br>koin-core = { module = &quot;io.insert-koin:koin-core&quot;, version.ref = &quot;koin&quot; }<br>koin-annotations = { module = &quot;io.insert-koin:koin-annotations&quot;, version.ref = &quot;koin&quot; }<br><br>[plugins]<br>koin-compiler = { id = &quot;io.insert-koin.compiler.plugin&quot;, version.ref = &quot;koin-plugin&quot; }</pre><pre>// root build.gradle.kts<br>plugins {<br>    // ... other plugins<br>    alias(libs.plugins.koin.compiler) apply false<br>}</pre><p>We centralize the Koin versions in the TOML file. By adding <em>alias(libs.plugins.koin.compiler) apply false</em> to the root <em>build.gradle.kts</em>, we force Gradle to download and resolve the plugin at the root level without actually applying it to the root project, making the plugin classes available to our <em>build-logic</em> convention module.</p><h4>Step 15: Create the Koin Convention Plugin</h4><p>Create <em>KoinConventionPlugin.kt</em> inside <em>build-logic/convention/src/main/kotlin:</em></p><pre>// build-logic/convention/src/main/kotlin/KoinConventionPlugin.kt<br>class KoinConventionPlugin : Plugin&lt;Project&gt; {<br>    override fun apply(target: Project) {<br>        with(target) {<br>            with(pluginManager) {<br>                apply(libs.findPlugin(&quot;koin-compiler&quot;).get().get().pluginId)<br>            }<br><br>            dependencies {<br>                add(&quot;implementation&quot;, libs.findLibrary(&quot;koin-core&quot;).get())<br>                add(&quot;implementation&quot;, libs.findLibrary(&quot;koin-annotations&quot;).get())<br>            }<br>        }<br>    }<br>}</pre><p>This plugin applies the Koin compiler plugin to the target module dynamically using <em>libs.findPlugin(…)</em>. It then automatically injects the <em>koin-core</em> and <em>koin-annotations</em> dependencies, meaning any module applying this convention instantly gets full Koin support.</p><h4>Step 16: Register the Koin Plugin in the Convention Build File</h4><p>Add the registration block to the <em>gradlePlugin</em> section in <em>build-logic/convention/build.gradle.kts:</em></p><pre>// build-logic/convention/build.gradle.kts<br>    plugins {<br>        // ... previously registered plugins (androidLibrary, androidLibraryCompose)<br>        <br>        register(&quot;koin&quot;) {<br>            id = libs.plugins.convention.koin.get().pluginId<br>            implementationClass = &quot;KoinConventionPlugin&quot;<br>        }<br>    }<br>}</pre><p>This maps our custom plugin ID to the <em>KoinConventionPlugin </em>class. When a module requests this plugin ID, Gradle knows to execute it.</p><h4>Step 17: Define the Custom Plugin ID in the Version Catalog</h4><p>Add the custom plugin ID to the <em>[plugins]</em> section of your root <em>gradle/libs.versions.toml:</em></p><pre># gradle/libs.versions.toml<br>[plugins]<br># ... previously defined plugins<br>convention-koin = { id = &quot;convention.koin&quot; }</pre><p>This creates the <em>convention.koin</em> plugin ID, which translates to the type-safe accessor <em>libs.plugins.convention.koin</em> used in Step 16.</p><h4>Step 18: Apply the Koin Convention Plugin in Target Modules</h4><p>In any module that requires Koin for dependency injection, apply the convention plugin in its <em>build.gradle.kts</em>:</p><pre>// app/feature-module/build.gradle.kts<br>plugins {<br>    // ... other convention plugins<br>    alias(libs.plugins.convention.koin)<br>}</pre><p>By adding this single line, the module automatically applies the Koin compiler plugin and adds the necessary dependencies, keeping module-level build files clean.</p><h4>Detekt</h4><p>To maintain code quality and enforce a consistent coding style, we can create a convention plugin for Detekt. This automatically configures Detekt, applies necessary rule sets (like Ktlint and Compose rules), and links a centralized configuration file.</p><h4>Step 19: Add Detekt Dependencies to Version Catalog</h4><p>Add the Detekt libraries to the <em>[libraries]</em> section of your root <em>gradle/libs.versions.toml</em> file:</p><pre># gradle/libs.versions.toml<br>[versions]<br>detekt = &quot;2.0.0-alpha.5&quot;<br>detekt-compose = &quot;0.6.3&quot;<br><br>[libraries]<br># ... existing libraries<br>detekt-gradlePlugin = { module = &quot;dev.detekt:detekt-gradle-plugin&quot;, version.ref = &quot;detekt&quot; }<br>detekt-ktlint = { module = &quot;dev.detekt:detekt-rules-ktlint-wrapper&quot;, version.ref = &quot;detekt&quot; }<br>detekt-compose = { module = &quot;io.nlopez.compose.rules:detekt&quot;, version.ref = &quot;detekt-compose&quot; }</pre><p>We centralize the Detekt Gradle plugin and the rule sets in the version catalog, ensuring all modules use the exact same Detekt version and rules.</p><h4>Step 20: Add Detekt Gradle Plugin to Convention Dependencies</h4><p>Add the Detekt Gradle plugin as an <em>implementation </em>dependency in <em>build-logic/convention/build.gradle.kts</em> and sync the project:</p><pre>// build-logic/convention/build.gradle.kts<br>dependencies {<br>    // ... existing dependencies<br>    implementation(libs.detekt.gradlePlugin)<br>}</pre><p>Unlike the Android Gradle Plugin (which was <em>compileOnly</em>), we use <em>implementation</em> for the Detekt plugin. The Detekt classes (like <em>DetektExtension</em> and <em>Detekt</em> tasks) need to be fully available at runtime for our convention plugin to configure them properly.</p><h4>Step 21: Create Detekt Configuration File</h4><p>Create a <em>config</em> package in the root of your project. Inside it, create a <em>detekt.yml</em> file and add your desired Detekt, Ktlint, and Compose rules.<br>This YAML file acts as the single source of truth for your code quality rules. Placing it in the root <em>config</em> package allows all modules to easily reference it, ensuring uniform linting across the entire project.</p><h4>Step 22: Create Detekt Convention Plugin and Helper</h4><p>Create <em>DetektConventionPlugin.kt</em> inside <em>build-logic/convention/src/main/kotlin</em>:</p><pre>// build-logic/convention/src/main/kotlin/DetektConventionPlugin.kt<br>class DetektConventionPlugin : Plugin&lt;Project&gt; {<br>    override fun apply(target: Project) {<br>        with(target) {<br>            with(pluginManager) {<br>                apply(&quot;dev.detekt&quot;)<br>            }<br><br>            extensions.configure&lt;DetektExtension&gt; {<br>                configureDetekt(this)<br>            }<br><br>            dependencies {<br>                add(&quot;detektPlugins&quot;, libs.findLibrary(&quot;detekt-ktlint&quot;).get())<br>                add(&quot;detektPlugins&quot;, libs.findLibrary(&quot;detekt-compose&quot;).get())<br>            }<br>        }<br>    }<br>}</pre><p>Create <em>Detekt.kt</em> inside <em>build-logic/convention/src/main/kotlin/com/convnetionplayground/convention:</em></p><pre>// build-logic/convention/src/main/kotlin/com/conventionplayground/convention/Detekt.kt<br>internal fun Project.configureDetekt(<br>    detektExtension: DetektExtension<br>){<br>    detektExtension.apply {<br>        buildUponDefaultConfig.set(true)<br>        autoCorrect.set(false)<br>        config.setFrom(files(&quot;$rootDir/config/detekt.yml&quot;))<br>    }<br><br>    tasks.withType&lt;Detekt&gt;().configureEach {<br>        reports {<br>            html.required.set(true)<br>            checkstyle.required.set(true)<br>            sarif.required.set(true)<br>            markdown.required.set(true)<br>        }<br>    }<br>}</pre><p>The plugin applies <em>dev.detekt</em>, configures the extension via the helper, and adds the Ktlint and Compose rule sets to the <em>detektPlugins</em> configuration. The helper sets up Detekt to build upon the default config, disables auto-correct (so it only reports issues), points to the centralized <em>detekt.yml</em> file, and configures multiple report formats for better CI/CD integration.</p><h4>Step 23: Define the Custom Plugin ID in the Version Catalog</h4><p>Add the custom plugin ID to the <em>[plugins]</em> section of your root <em>gradle/libs.versions.toml</em>:</p><pre># gradle/libs.versions.toml<br>[plugins]<br># ... previously defined plugins<br>convention-detekt = { id = &quot;convention.detekt&quot; }</pre><p>This creates the <em>convention.detekt</em> plugin ID, translating to the type-safe accessor <em>libs.plugins.convention.detekt</em>.</p><h4>Step 24: Register the Detekt Plugin in the Convention Build File</h4><p>Add the registration block to the <em>gradlePlugin </em>section in <em>build-logic/convention/build.gradle.kts</em>:</p><pre>// build-logic/convention/build.gradle.kts<br>gradlePlugin {<br>    plugins {<br>        // ... previously registered plugins<br>        <br>        register(&quot;detekt&quot;){<br>            id = libs.plugins.convention.detekt.get().pluginId<br>            implementationClass = &quot;DetektConventionPlugin&quot;<br>        }<br>    }<br>}</pre><p>This maps the custom <em>convention.detekt</em> plugin ID to the <em>DetektConventionPlugin </em>class, completing the wiring process.</p><h4>Step 25: Apply the Detekt Convention Plugin in Target Modules</h4><p>In any module where you want to enforce code quality checks, apply the convention plugin in its <em>build.gradle.kts</em>:</p><pre>// app/feature-module/build.gradle.kts<br>plugins {<br>    // ... other convention plugins<br>    alias(libs.plugins.convention.detekt)<br>}</pre><p>By adding this single line, the module automatically applies Detekt, links the centralized configuration file, and includes the Ktlint and Compose rule sets, guaranteeing uniform linting without duplicating configuration.</p><h3>Part 3: Aggregated Feature Plugin</h3><p>As your project grows, applying multiple individual convention plugins to every feature module can become repetitive. To solve this, we can create a “meta” or aggregated convention plugin that applies all the necessary base plugins for a standard feature module in one go.</p><h4>Step 26: Create the Android Feature Convention Plugin</h4><p>Create <em>AndroidFeatureConventionPlugin.kt</em> inside <em>build-logic/convention/src/main/kotlin</em>:</p><pre>// build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt<br>class AndroidFeatureConventionPlugin : Plugin&lt;Project&gt; {<br>    override fun apply(target: Project) {<br>        with(target) {<br>            with(pluginManager) {<br>                apply(&quot;convention.android.library&quot;)<br>                apply(&quot;convention.compose&quot;)<br>                apply(&quot;convention.koin&quot;)<br>                apply(&quot;convention.detekt&quot;)<br>            }<br>        }<br>    }<br>}</pre><p>This plugin acts as an aggregator. Instead of configuring extensions or adding dependencies directly, it simply applies the four convention plugins we created in the previous steps using their string IDs. This explicitly defines what a “Feature Module” is in your architecture.</p><h4>Step 27: Define the Custom Plugin ID in the Version Catalog</h4><p>Add the custom plugin ID to the <em>[plugins]</em> section of your root <em>gradle/libs.versions.toml</em>:</p><pre># gradle/libs.versions.toml<br>[plugins]<br># ... previously defined plugins<br>convention-android-feature = { id = &quot;convention.android.feature&quot; }</pre><p>This registers the new <em>convention.android.feature</em> plugin ID in the version catalog, allowing us to use the type-safe accessor in our build scripts.</p><h4>Step 28: Register the Feature Plugin in the Convention Build File</h4><p>Add the registration block to the <em>gradlePlugin</em> section in <em>build-logic/convention/build.gradle.kts</em> and sync the project:</p><pre>// build-logic/convention/build.gradle.kts<br>gradlePlugin {<br>    plugins {<br>        // ... previously registered plugins<br>        <br>        register(&quot;androidFeature&quot;) {<br>            id = libs.plugins.convention.android.feature.get().pluginId<br>            implementationClass = &quot;AndroidFeatureConventionPlugin&quot;<br>        }<br>    }<br>}</pre><p>This finalizes the wiring for the aggregated plugin, mapping the ID to our <em>AndroidFeatureConventionPlugin </em>class.</p><h4>Step 29: Apply the Aggregated Plugin in Target Feature Modules</h4><p>In any feature module’s <em>build.gradle.kts</em>, replace the multiple individual plugin aliases with the single feature alias, and sync the project:</p><p>Verbose:</p><pre>// app/feature-module/build.gradle.kts<br>plugins {<br>    alias(libs.plugins.convention.android.library)<br>    alias(libs.plugins.convention.compose)<br>    alias(libs.plugins.convention.koin)<br>    alias(libs.plugins.convention.detekt)<br>}</pre><p>Clean:</p><pre>// app/feature-module/build.gradle.kts<br>plugins {<br>    alias(libs.plugins.convention.android.feature)<br>}</pre><p>This is the ultimate payoff. By applying just one line, the module automatically inherits the Android base configuration, Jetpack Compose setup, Koin dependency injection, and Detekt code quality rules. This drastically reduces boilerplate, makes the purpose of the module immediately clear to other developers, and ensures strict architectural consistency.</p><h3>Beyond the Basics: Extending Your Convention Plugins</h3><p>The beauty of the <em>build-logic</em> pattern is that it is infinitely extensible. Once you have this foundation, you can create specialized convention plugins for any specific architectural need in your project. Here are several powerful examples you can add next to further streamline your multi-module setup:</p><ol><li><strong>Android Application Plugin:</strong> Applies the <em>com.android.application</em> plugin, sets the <em>applicationId</em>, configures signing configs, sets up ProGuard/R8 rules, and enables specific build features like <em>buildConfig</em> that only the final APK/AAB needs.</li><li><strong>Pure Kotlin Library Plugin: </strong>Applies the <em>org.jetbrains.kotlin.jvm</em> plugin, configures JVM target compatibility, and automatically injects testing frameworks like JUnit 5 and MockK. This keeps your core logic fast to compile and platform-agnostic.</li><li><strong>Room Database Plugin:</strong> Applies the KSP plugin, adds the Room runtime and compiler dependencies from your version catalog, and automatically configures the <em>room.schemaLocation</em> argument so your database schemas are exported consistently for migration testing.</li></ol><p>By treating your build configuration as code, you transform Gradle from a source of friction into a powerful tool that actively enforces your team’s architectural standards.</p><p>You can have access to the complete project source code and structure via the <a href="https://github.com/AlirezaPK/ConventionPlayground">GitHub</a> link.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=798ee02f4c51" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>