<?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 Reza Zavareh on Medium]]></title>
        <description><![CDATA[Stories by Reza Zavareh on Medium]]></description>
        <link>https://medium.com/@reza.zavareh7?source=rss-d09c04f2bdc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XqeA0r4tfhiK-CuCfNUrBQ.jpeg</url>
            <title>Stories by Reza Zavareh on Medium</title>
            <link>https://medium.com/@reza.zavareh7?source=rss-d09c04f2bdc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:53:02 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@reza.zavareh7/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[Gradle Convention Plugin(Part 3, Build Configuration)]]></title>
            <link>https://medium.com/@reza.zavareh7/gradle-convention-plugin-part-3-build-configuration-f5aa68125c10?source=rss-d09c04f2bdc------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5aa68125c10</guid>
            <category><![CDATA[modular]]></category>
            <category><![CDATA[gradle-convention-plugin]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[build-configuration]]></category>
            <dc:creator><![CDATA[Reza Zavareh]]></dc:creator>
            <pubDate>Sun, 10 Aug 2025 03:44:25 GMT</pubDate>
            <atom:updated>2025-08-10T03:44:25.515Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3YFShO9tnCdt0Uy31J076w.png" /></figure><p>Hi everyone, <br>In the previous parts, we learned how to create the <a href="https://medium.com/@reza.zavareh7/gradle-convention-plugin-d0651a9fcaad"><strong>MoshiConventionPlugin(Part 1)</strong></a> and the <a href="https://medium.com/@reza.zavareh7/gradle-convention-plugin-part-2-flavors-1a905d79b30b"><strong>FlavorsConventionPlugin(Part 2)</strong></a><strong>.</strong></p><p>In the final guide of our series, we’ll create the <strong>AndroidApplicationConventionPlugin</strong>. The goal is to replace the standard com.android.application plugin setup in our app module&#39;s build.gradle file, leading to a much cleaner and more maintainable project.</p><p>We will use the previously created plugins to the AndroidApplicationConventionPlugin to remove <strong>build configurations</strong>, <strong>flavors</strong>, and <strong>dependencies</strong>—such as Moshi and:core:networkfrom the app’s Gradle file.</p><p>Our plugin will be designed for an <strong>Android Application Module</strong> (like :app) by configuring it in the <strong>ApplicationExtension</strong>. The process involves three familiar steps:</p><p><strong>1. Create Your Convention Plugin.</strong></p><p><strong>2. Register the Convention Plugin.</strong></p><p><strong>3. Apply the Convention Plugin in a module.</strong></p><p><strong>Note:</strong> To get the most out of this guide, it’s highly recommended that you review the <strong>previous articles</strong> in this series first.</p><ol><li><strong>Create Your Convention Plugin.</strong></li></ol><p>We previously defined the build configuration versions in libs.versions.toml.</p><pre>[versions]<br>appVersion = &quot;100&quot;<br>android-compileSdk = &quot;36&quot;<br>android-minSdk = &quot;24&quot;<br>android-targetSdk = &quot;35&quot;</pre><p>Let’s create the AndroidApplicationConventionPlugin in the convention module.</p><pre>package com.test.convention<br><br>import com.android.build.api.dsl.ApplicationExtension<br>import org.gradle.api.JavaVersion<br>import org.gradle.api.Plugin<br>import org.gradle.api.Project<br>import org.gradle.kotlin.dsl.dependencies<br><br>class AndroidApplicationConventionPlugin : Plugin&lt;Project&gt; {<br>    override fun apply(project: Project): Unit = with(project) {<br>        val libs = getLibs()<br>        <br>        // We have already registered moshi-convention and flavors-convention <br>        plugins.apply(libs.findPlugin(&quot;android-application&quot;).get().get().pluginId)<br>        plugins.apply(libs.findPlugin(&quot;moshi-convention&quot;).get().get().pluginId)<br>        plugins.apply(libs.findPlugin(&quot;flavors-convention&quot;).get().get().pluginId)<br><br>        extensions.getByType(ApplicationExtension::class.java).apply {<br>            namespace = &quot;com.test.testapp&quot;<br>            compileSdk = libs.findVersion(&quot;android-compileSdk&quot;).get().requiredVersion.toInt()<br>            defaultConfig {<br>                minSdk = libs.findVersion(&quot;android-minSdk&quot;).get().requiredVersion.toInt()<br>                targetSdk = libs.findVersion(&quot;android-targetSdk&quot;).get().requiredVersion.toInt()<br>                applicationId = &quot;com.test.testapp&quot;<br>                versionCode = libs.findVersion(&quot;appVersion&quot;).get().requiredVersion.toInt()<br>                versionName = libs.findVersion(&quot;appVersion&quot;).get().requiredVersion.toCharArray()<br>                    .joinToString(&quot;.&quot;)<br>                testInstrumentationRunner = &quot;androidx.test.runner.AndroidJUnitRunner&quot;<br>            }<br><br>            compileOptions {<br>                sourceCompatibility = JavaVersion.VERSION_21<br>                targetCompatibility = JavaVersion.VERSION_21<br>            }<br><br>            buildFeatures {<br>                buildConfig = true<br>                compose = true<br>            }<br>            packaging.resources.excludes += &quot;/META-INF/{AL2.0,LGPL2.1}&quot;<br><br>            buildTypes {<br>                debug {<br>                    isMinifyEnabled = false<br>                    isDebuggable = true<br>                    applicationIdSuffix = BuildType.DEBUG.applicationIdSuffix<br>                }<br><br>                release {<br>                    isMinifyEnabled = true<br>                    isShrinkResources = true<br>                    applicationIdSuffix = BuildType.RELEASE.applicationIdSuffix<br>                    proguardFiles(<br>                        getDefaultProguardFile(&quot;proguard-android-optimize.txt&quot;),<br>                        &quot;proguard-rules.pro&quot;,<br>                    )<br>                }<br>            }<br><br>            dependencies {<br>                add(&quot;implementation&quot;, libs.findLibrary(&quot;androidx-core-ktx&quot;).get())<br>                add(&quot;implementation&quot;, libs.findLibrary(&quot;androidx-lifecycle-runtime-ktx&quot;).get())<br>                // Additional dependencies can be implemented here.<br><br>                &quot;implementation&quot;(project(&quot;:core:network&quot;))<br>                // Sample implementation of a module in a convention plugin<br><br>            }<br>        }<br>    }<br>}</pre><pre>enum class BuildType(val applicationIdSuffix: String? = null) {<br>    DEBUG(&quot;.debug&quot;),<br>    RELEASE,<br>}</pre><p>The Application Convention Plugin has been created.</p><p><strong>Note 1:</strong> You can apply other convention plugins within a convention plugin just like regular plugins.</p><p><strong>Note 2: </strong>The AndroidApplicationConventionPlugin is for an <strong>Android Application Module</strong> like :app module, but if you want to have the same convention plugin in an <strong>Android Library Module</strong>, you have to create it in the <strong>LibraryExtension.</strong><br>I put a sample of it here, and you can follow the next steps to use it in a module like the :core:network to remove <strong>build configuration</strong> lines.</p><pre>class AndroidLibraryConventionPlugin: Plugin&lt;Project&gt; {<br>    override fun apply(project: Project): Unit = with(project) {<br>        val libs = getLibs()<br>        <br>        plugins.apply(libs.findPlugin(&quot;android-library&quot;).get().get().pluginId)   <br><br>        extensions.getByType(LibraryExtension::class.java).apply {<br>            namespace = &quot;com.test.${project.name}&quot;<br>            compileSdk = libs.findVersion(&quot;android-compileSdk&quot;).get().requiredVersion.toInt()<br>            defaultConfig {<br>                minSdk = libs.findVersion(&quot;android-minSdk&quot;).get().requiredVersion.toInt()<br>                testInstrumentationRunner = &quot;androidx.test.runner.AndroidJUnitRunner&quot;<br>            }<br><br>            compileOptions {<br>                sourceCompatibility = JavaVersion.VERSION_21<br>                targetCompatibility = JavaVersion.VERSION_21<br>            }<br><br>            buildFeatures {<br>                buildConfig = true<br>                compose = true<br>            }<br>            packaging.resources.excludes += &quot;/META-INF/{AL2.0,LGPL2.1}&quot;<br>        }<br>    }<br>}</pre><p><strong>2. Register the Convention Plugin.</strong></p><p>Define the created convention plugin as a plugin in the libs.versions.toml</p><pre>[plugins]<br>android-application-convention = { id = &quot;com.test.convention.android.application&quot; }</pre><p>Next, <strong>register </strong>AndroidApplicationConventionPlugin.kts in convention/build.gradle.kts to make the plugin available for use.</p><pre>gradlePlugin {<br>     register(&quot;AndroidApplicationConventionPlugin&quot;) {<br>            id = libs.plugins.android.application.convention.get().pluginId<br>            implementationClass = &quot;com.test.convention.AndroidApplicationConventionPlugin&quot;<br>        }<br><br>      // We’ve already registered the FlavorsConventionPlugin and MoshiConventionPlugin.<br>}</pre><h4>4. Apply the Convention Plugin in Your Modules.</h4><p>Finally, remove all <strong>Moshi</strong>, <strong>Flavors</strong>, and <strong>build configuration</strong> lines from the app module, and replace them with the android-application-convention plugin.</p><p>You can then compare the app/build.gradle.kts file before and after applying the convention plugin.</p><p>If your app’s Gradle file contains the following configuration, it can now be refactored and simplified as shown below:</p><pre>plugins {<br>    alias(libs.plugins.android.application)<br>    alias(libs.plugins.ksp)<br>}<br><br>android {<br>    namespace = &quot;ir.test.testapp&quot;<br>    compileSdk = libs.versions.android.compileSdk.get().toInt()<br><br>    defaultConfig {<br>        applicationId = &quot;ir.test.testapp&quot;<br>        minSdk = libs.versions.android.minSdk.get().toInt()<br>        targetSdk = libs.versions.android.targetSdk.get().toInt()<br>        versionCode = libs.versions.appVersion.get().toInt()<br>        versionName = libs.versions.appVersion.get().toCharArray().joinToString(&quot;.&quot;)<br><br>        testInstrumentationRunner = &quot;androidx.test.runner.AndroidJUnitRunner&quot;<br>    }<br><br>    flavorDimensions.add(&quot;TestApp&quot;)<br><br>    productFlavors {<br>        create(&quot;dev&quot;) {<br>            dimension = &quot;TestApp&quot;<br>            applicationIdSuffix = &quot;.dev&quot;<br>            versionNameSuffix = &quot;-dev&quot;<br>            buildConfigField(&quot;String&quot;, &quot;WALLET_BASE_URL&quot;, &quot;\&quot;http://10.20.30.40:5060/\&quot;&quot;)<br>            buildConfigField(&quot;String&quot;, &quot;AUTH_BASE_URL&quot;, &quot;\&quot;http://70.80.90.100:1020/\&quot;&quot;)<br>        }<br>        create(&quot;uat&quot;) {<br>            dimension = &quot;TestApp&quot;<br>            applicationIdSuffix = &quot;.uat&quot;<br>            versionNameSuffix = &quot;-uat&quot;<br>            buildConfigField(<br>                &quot;String&quot;,<br>                &quot;WALLET_BASE_URL&quot;,<br>                &quot;\&quot;https://wallet-uat/walletbackend/\&quot;&quot;,<br>            )<br>            buildConfigField(&quot;String&quot;, &quot;AUTH_BASE_URL&quot;, &quot;\&quot;https://auth-uat/authbackend/\&quot;&quot;)<br>        }<br>        create(&quot;prod&quot;) {<br>            dimension = &quot;TestApp&quot;<br>            buildConfigField(&quot;String&quot;, &quot;WALLET_BASE_URL&quot;, &quot;\&quot;https://wallet/walletbackend/\&quot;&quot;)<br>            buildConfigField(&quot;String&quot;, &quot;AUTH_BASE_URL&quot;, &quot;\&quot;https://auth/authbackend/\&quot;&quot;)<br>        }<br>    }<br><br>    compileOptions {<br>        sourceCompatibility = JavaVersion.VERSION_21<br>        targetCompatibility = JavaVersion.VERSION_21<br>    }<br><br>    buildFeatures {<br>        buildConfig = true<br>        compose = true<br>    }<br><br>    packaging {<br>        resources {<br>            excludes += &quot;/META-INF/{AL2.0,LGPL2.1}&quot;<br>        }<br>    }<br><br>    buildTypes {<br>        debug {<br>            isMinifyEnabled = false<br>            isDebuggable = true<br>            applicationIdSuffix = &quot;.debug&quot;<br>        }<br><br>        release {<br>            isMinifyEnabled = true<br>            isShrinkResources = true<br>            proguardFiles(<br>                getDefaultProguardFile(&quot;proguard-android-optimize.txt&quot;),<br>                &quot;proguard-rules.pro&quot;,<br>            )<br>        }<br>    }<br>}<br><br>dependencies {<br><br>    // Moshi<br>    implementation(libs.moshi.converter)<br>    implementation(libs.moshi)<br>    ksp(libs.moshi.codegen)<br><br>    // Modules<br>    implementation(projects.core.network)<br>}</pre><p>Following the refactor :</p><pre>plugins {<br>    // Apply the convention plugin<br>    alias(libs.plugins.android.application.convention)<br>}<br><br>// All other configurations have been removed</pre><p>Now you can see that <strong>build configurations</strong>, f<strong>lavors</strong>, <strong>dependencies </strong>such as <strong>Moshi </strong>and the <strong>network module,</strong> are no longer required.</p><p>If you want to learn how to create the <a href="https://medium.com/@reza.zavareh7/gradle-convention-plugin-d0651a9fcaad"><strong>MoshiConventionPlugin </strong></a>and <a href="https://medium.com/@reza.zavareh7/gradle-convention-plugin-part-2-flavors-1a905d79b30b"><strong>FlavorsConventionPlugin</strong></a><strong>, </strong>please refer to the previous articles.</p><p>I’ve created three different types of convention plugins to help you eliminate some of the extra code in your modules’ Gradle files.</p><p>This will be helpful to you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5aa68125c10" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gradle Convention Plugin(Part2, Flavors)]]></title>
            <link>https://medium.com/@reza.zavareh7/gradle-convention-plugin-part-2-flavors-1a905d79b30b?source=rss-d09c04f2bdc------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a905d79b30b</guid>
            <category><![CDATA[modular]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[gradle-convention-plugin]]></category>
            <dc:creator><![CDATA[Reza Zavareh]]></dc:creator>
            <pubDate>Sun, 03 Aug 2025 11:20:13 GMT</pubDate>
            <atom:updated>2025-08-03T11:44:32.574Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3YFShO9tnCdt0Uy31J076w.png" /></figure><p>Hi everyone,<br>In the <a href="https://medium.com/@reza.zavareh7/gradle-convention-plugin-d0651a9fcaad">previous </a>article, we explored the concept of Gradle Convention Plugins and how they help reduce repetitive Gradle code. In this article, we’ll take it a step further by implementing a <strong>flavor convention plugin</strong> together.</p><p>The main reason I started learning about convention plugins was to clean up my Gradle files. In my modular Android project, I found myself repeatedly copying and pasting the same flavor configurations into every new feature module — and it quickly became a maintenance headache.</p><p>If you haven’t read the first article yet, I recommend checking it out first to better understand the foundation of convention plugins and get the most out of this guide.</p><p>Because we need to define flavors in <strong>Android application modules(App Module)</strong> and <strong>Android library modules(Feature Modules)</strong>, we need the <strong>Application Extension, Android Extension,</strong> and the <strong>Common Extension</strong> to share some logic and code between them.</p><p>We’re going to follow these steps:</p><p><strong>1. Define and prepare the required data</strong></p><p><strong>2. Create Your Convention Plugin.</strong></p><p><strong>3. Register the Convention Plugin.</strong></p><p><strong>4. Apply the Convention Plugin in Your Modules.</strong></p><p>For our sample project, we will create <strong>three flavors</strong>: dev, uat, and prod. Each flavor will have two distinct <strong>Base URLs</strong>—one for <strong>authentication </strong>and one for the <strong>wallet </strong>service. We will then apply our flavor convention plugin to both the <strong>app module</strong> (ApplicationExtension) and the <strong>network module</strong> (LibraryExtension).</p><h4><strong>1. Define and prepare the required data</strong></h4><p>We start by defining key build configurations like <strong>flavor dimensions</strong>, <strong>product flavors</strong>, and their corresponding <strong>Base URLs</strong>.</p><p>Make FlavorDimension and TestAppFlavor classes in the convention module.</p><pre>enum class FlavorDimension {<br>    TestApp<br>}</pre><pre>@Suppress(&quot;EnumEntryName&quot;)<br>enum class TestAppFlavor(<br>    val dimension: FlavorDimension,<br>    val applicationIdSuffix: String? = null,<br>    val versionNameSuffix: String? = null<br>) {<br>    dev(<br>        dimension = FlavorDimension.TestApp,<br>        applicationIdSuffix = &quot;.dev&quot;,<br>        versionNameSuffix = &quot;-dev&quot;<br>    ),<br>    uat(<br>        dimension = FlavorDimension.TestApp,<br>        applicationIdSuffix = &quot;.uat&quot;,<br>        versionNameSuffix = &quot;-uat&quot;<br>    ),<br>    prod(dimension = FlavorDimension.TestApp),<br>}</pre><p>After defining the above classes, we make a flavors.properties file in the root of the project.</p><pre>dev.WALLET_BASE_URL=http://10.20.30.40:5060/<br>dev.AUTH_BASE_URL=http://70.80.90.1000:1020/<br><br>uat.WALLET_BASE_URL=https://wallet-uat/walletbackend/<br>uat.AUTH_BASE_URL=https://auth-uat/authbackend/<br><br>prod.WALLET_BASE_URL=https://wallet/walletbackend/<br>prod.AUTH_BASE_URL=https://auth/authbackend/</pre><h4><strong>2. Create Your Convention Plugin.</strong></h4><p>It&#39;s time to make the FlavorsConventionPlugin.kt in the convention module</p><pre>class FlavorsConventionPlugin : Plugin&lt;Project&gt; {<br>    override fun apply(project: Project) {<br>        project.plugins.withId(&quot;com.android.library&quot;) {<br>            project.extensions.configure&lt;LibraryExtension&gt; {<br>                configureFlavors(this, project)<br>            }<br>        }<br>        project.plugins.withId(&quot;com.android.application&quot;) {<br>            project.extensions.configure&lt;ApplicationExtension&gt; {<br>                configureFlavors(this, project)<br>            }<br>        }<br>    }<br>}</pre><p>When the com.android.library applied, the LibraryExtension registered and when com.android.application applied the ApplicationExtension registered to configure all aspects of your Android project.</p><pre>fun configureFlavors(<br>    commonExtension: CommonExtension&lt;*, *, *, *, *, *&gt;,<br>    project: Project,<br>    flavorConfigurationBlock: ProductFlavor.(flavor: PalizFlavor) -&gt; Unit = {},<br>) {<br>    val props = loadFlavorProperties(project)<br>    commonExtension.apply {<br>        FlavorDimension.values().forEach { flavorDimension -&gt;<br>            flavorDimensions += flavorDimension.name<br>        }<br><br>        productFlavors {<br>            TestAppFlavor.values().forEach { flavor -&gt;<br>                register(flavor.name) {<br>                    dimension = flavor.dimension.name<br><br>                    val walletUrl = props[&quot;$flavor.WALLET_BASE_URL&quot;] as? String<br>                    val authUrl = props[&quot;$flavor.AUTH_BASE_URL&quot;] as? String<br><br>                    if (this@apply is ApplicationExtension &amp;&amp; this is ApplicationProductFlavor) {<br>                        if (flavor.applicationIdSuffix != null)<br>                            applicationIdSuffix = flavor.applicationIdSuffix<br><br>                        if (flavor.versionNameSuffix != null)<br>                            versionNameSuffix = flavor.versionNameSuffix<br>                    }<br>                    buildConfigField(&quot;String&quot;, &quot;WALLET_BASE_URL&quot;, &quot;\&quot;$walletUrl\&quot;&quot;)<br>                    buildConfigField(&quot;String&quot;, &quot;AUTH_BASE_URL&quot;, &quot;\&quot;$authUrl\&quot;&quot;)<br>                    buildFeatures.buildConfig = true<br>                    flavorConfigurationBlock(this, flavor)<br>                }<br>            }<br>        }<br>    }<br>}<br><br><br>private fun loadFlavorProperties(project: Project): Properties {<br>    val props = Properties()<br>    val file = project.rootProject.file(&quot;flavors.properties&quot;)<br>    if (file.exists()) {<br>        props.load(file.inputStream())<br>    } else {<br>        throw GradleException(&quot;Missing flavors.properties file at project root.&quot;)<br>    }<br>    return props<br>}</pre><p>Read data from the flavors.properties file to set the BaseUrls for each flavor. We can also define applicationIdSuffix and versionNameSuffix for <strong>Android application modules</strong>. Finally, to use BuildConfig in your modules, you need to enable buildFeatures.buildConfig.</p><h4><strong>3. Register the Convention Plugin.</strong></h4><p>Define the created convention plugin as a plugin in the libs.versions.toml</p><pre>[plugins]<br>flavors-convention = {id = &quot;com.test.convention.flavors&quot;} // this id could be everything</pre><p>In the next step, we need to register the plugin to make it available for use.</p><p><strong>Register </strong>the FlavorsConventionPlugin.kts in the convention/build.gradle.kts</p><pre>gradlePlugin {<br>    plugins {<br>        register(&quot;FlavorsConventionPlugin&quot;) {<br>            id = libs.plugins.flavors.convention.get().pluginId<br>            implementationClass = &quot;com.test.convention.FlavorsConventionPlugin&quot;<br>        }<br>    }<br>}</pre><h4><strong>4. Apply the Convention Plugin in Your Modules.</strong></h4><p>Finally, you must remove <strong>all flavor codes</strong> and just replace the<strong> </strong>flavors-convention<strong> </strong>plugin.</p><p>Refactor the app/build.gradle.kts</p><pre>plugins {<br>    alias(libs.plugins.android.application) // Android application<br>    alias(libs.plugins.flavors.convention) // Apply the flavors convention plugin<br>}<br><br>    android {<br>                        // You can remove all flavors codes<br><br>//        flavorDimensions.add(&quot;TestApp&quot;)<br>//<br>//        productFlavors {<br>//            create(&quot;dev&quot;) {<br>//                dimension = &quot;TestApp&quot;<br>//                applicationIdSuffix = &quot;.dev&quot;<br>//                versionNameSuffix = &quot;-dev&quot;<br>//                buildConfigField(&quot;String&quot;, &quot;WALLET_BASE_URL&quot;, &quot;\&quot;http://10.20.30.40:5060/\&quot;&quot;)<br>//                buildConfigField(&quot;String&quot;, &quot;AUTH_BASE_URL&quot;, &quot;\&quot;http://70.80.90.100:1020/\&quot;&quot;)<br>//            }<br>//            create(&quot;uat&quot;) {<br>//                dimension = &quot;TestApp&quot;<br>//                applicationIdSuffix = &quot;.uat&quot;<br>//                versionNameSuffix = &quot;-uat&quot;<br>//                buildConfigField(<br>//                    &quot;String&quot;,<br>//                    &quot;WALLET_BASE_URL&quot;,<br>//                    &quot;\&quot;https://wallet-uat/walletbackend/\&quot;&quot;,<br>//                )<br>//                buildConfigField(&quot;String&quot;, &quot;AUTH_BASE_URL&quot;, &quot;\&quot;https://auth-uat/authbackend/\&quot;&quot;)<br>//            }<br>//            create(&quot;prod&quot;) {<br>//                dimension = &quot;TestApp&quot;<br>//                buildConfigField(&quot;String&quot;, &quot;WALLET_BASE_URL&quot;, &quot;\&quot;https://wallet/walletbackend/\&quot;&quot;)<br>//                buildConfigField(&quot;String&quot;, &quot;AUTH_BASE_URL&quot;, &quot;\&quot;https://auth/authbackend/\&quot;&quot;)<br>//            }<br>//        }<br>    }</pre><p>Refactor the network/build.gradle.kts same above</p><pre>plugins {<br>    alias(libs.plugins.android.library)    // Android library<br>    alias(libs.plugins.flavors.convention) // Apply the flavors convention plugin<br>}<br><br>    android {<br>       // You can remove all flavors codes<br>    }</pre><p>That’s great! Now your Gradle files are much <strong>cleaner.</strong></p><p>I hope this was helpful to you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a905d79b30b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gradle Convention Plugin]]></title>
            <link>https://medium.com/@reza.zavareh7/gradle-convention-plugin-d0651a9fcaad?source=rss-d09c04f2bdc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0651a9fcaad</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[modular]]></category>
            <category><![CDATA[kotlin-native]]></category>
            <category><![CDATA[gradle-convention-plugin]]></category>
            <dc:creator><![CDATA[Reza Zavareh]]></dc:creator>
            <pubDate>Sat, 02 Aug 2025 08:33:39 GMT</pubDate>
            <atom:updated>2025-08-10T03:45:59.103Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3YFShO9tnCdt0Uy31J076w.png" /></figure><p>Hi Everyone,<br>This article is for anyone who wants to keep their Gradle files clean and avoid repeating the same code across modules.</p><p>In a modular app, you often have to repeat the same plugins, dependencies, build types, and flavor configurations in each feature module’s build.gradle file.</p><p>Gradle convention plugins are a great solution, but they can be a bit tricky to understand at first. I had a hard time finding clear documentation, so I hope this guide helps make it easier for you.</p><p>When you’re working with <strong>Gradle convention plugins</strong>, you’ll commonly encounter a few <strong>Gradle extensions</strong> across your convention plugins.</p><p>So it&#39;s a good idea to explain some of them before starting the steps:</p><h4><strong>1. ApplicationExtension:</strong></h4><p>You use it in your convention plugin when configuring <strong>Android application modules</strong>(ones that apply the com.android.application plugin).</p><h4><strong>2. LibraryExtension:</strong></h4><p>You use it in your convention plugin when configuring <strong>Android library modules</strong>(ones that apply the com.android.library plugin).</p><h4><strong>3. CommonExtension:</strong></h4><p>This is a <strong>generic interface</strong> introduced to <strong>unify shared logic</strong> between application and library modules.<br>You use it to write <strong>shared configuration code</strong> in a reusable way</p><h4><strong>4. VersionCatalogsExtension:</strong></h4><p>You use it in your convention plugin to <strong>access your </strong>libs.versions.toml<strong> dependencies and versions.</strong></p><p>OK, if you&#39;re ready, let&#39;s go to implement your first Gradle convention plugin</p><p>We&#39;re going to follow these steps:</p><p><strong>1. Define and prepare the </strong>build-logic<strong> module</strong></p><p><strong>2. Create Your Convention Plugin.</strong></p><p><strong>3. Register the Convention Plugin.</strong></p><p><strong>4. Apply the Convention Plugin in Your Modules.</strong></p><p>We’ll go through these steps to create a simple Gradle convention (a Moshi convention plugin) and use it in our project. In the next level, we’ll dive into more advanced convention plugins — like handling build types and product flavors ;)</p><h4><strong>1. Define and prepare the </strong>build-logic<strong> module</strong></h4><p>Make your build-logic module like this diagram.</p><p>root/<br>├── app/<br>├── feature-profile/<br>├──<strong> build-logic/ ← </strong>your custom convention plugins live here<strong><br>│ ├── convention/<br>│ │ └── build.gradle.kts<br>│ └── settings.gradle.kts</strong><br>├── build.gradle.kts<br>├── settings.gradle.kts<br>└── gradle/libs.versions.toml</p><p>Define the convention module inside the build-logic/settings.gradle.kts</p><pre>rootProject.name = &quot;build-logic&quot;<br>include(&quot;:convention&quot;)</pre><p>And set build-logic as a <strong>plugin management repo</strong> in the <strong>root </strong>settings.gradle.kts</p><pre>pluginManagement {<br>    includeBuild(&quot;build-logic&quot;)<br>}</pre><p>Define essential plugins in the libs.versions.toml</p><pre>androidGradlePlugin = { group = &quot;com.android.tools.build&quot;, name = &quot;gradle&quot;, version.ref = &quot;agp&quot; }<br>kotlinGradlePlugin = { group = &quot;org.jetbrains.kotlin&quot;, name = &quot;kotlin-gradle-plugin&quot;, version.ref = &quot;kotlin&quot; }</pre><p>Now we need a Kotlin-Base Gradle as the convention/build.gradle.kts</p><pre>plugins {<br>    `kotlin-dsl`<br>}<br>dependencies {<br>   compileOnly(libs.androidGradlePlugin)<br>   compileOnly(libs.kotlinGradlePlugin)<br>}<br>kotlin {<br>    jvmToolchain {<br>        languageVersion.set(JavaLanguageVersion.of(JavaVersion.VERSION_21.majorVersion.toInt()))<br>    }<br>}<br><br>gradlePlugin {<br>    plugins {<br>        // we will register our conventions here<br>    }<br>}</pre><h4><strong>2. Create Your Convention Plugin.</strong></h4><p>In this step, the build-logic is ready to make the <strong>Moshi </strong>convention plugin.</p><p>At first, we have to access thelibs.versions.toml, so we add this code inside the build-logic/settings.gradle.kts</p><pre>dependencyResolutionManagement {<br>    versionCatalogs {<br>        create(&quot;libs&quot;) {<br>            from(files(&quot;../gradle/libs.versions.toml&quot;))<br>        }<br>    }<br>}</pre><p>Define the <strong>Moshi </strong>library inside the libs.versions.toml</p><pre>[versions]<br>ksp = &quot;2.2.0-2.0.2&quot;<br>moshiConverter = &quot;3.0.0&quot;<br>moshi = &quot;1.15.2&quot;<br><br>[libraries]<br>moshi-converter= {group = &quot;com.squareup.retrofit2&quot;, name= &quot;converter-moshi&quot;, version.ref =&quot;moshiConverter&quot;}<br>moshi = {group= &quot;com.squareup.moshi&quot;, name = &quot;moshi-kotlin&quot;, version.ref= &quot;moshi&quot;}<br>moshi-codegen = {group= &quot;com.squareup.moshi&quot;, name = &quot;moshi-kotlin-codegen&quot;, version.ref= &quot;moshi&quot;}<br><br>[plugins]<br>ksp = {id = &quot;com.google.devtools.ksp&quot;, version.ref = &quot;ksp&quot;}</pre><p>And we can use an extension function to get the libs.versions.toml values in the convention module.</p><pre>fun Project.getLibs(): VersionCatalog =<br>    extensions.getByType&lt;VersionCatalogsExtension&gt;().named(&quot;libs&quot;)</pre><p>Now it’s time to create your convention plugin file here.</p><p>root/<br>├── app/<br>├──<strong> build-logic/ <br>│ ├── convention/ </strong>← your<strong> </strong>plugin conventions</p><pre>package com.test.convention<br><br>import org.gradle.api.Plugin<br>import org.gradle.api.Project<br>import org.gradle.kotlin.dsl.dependencies<br><br>class MoshiConventionPlugin: Plugin&lt;Project&gt; {<br>    override fun apply(project: Project): Unit = with(project) {<br>        val libs = getLibs()<br>        plugins.apply(libs.findPlugin(&quot;ksp&quot;).get().get().pluginId)<br><br>        dependencies {<br>            add(&quot;implementation&quot;, libs.findLibrary(&quot;moshi-converter&quot;).get())<br>            add(&quot;implementation&quot;, libs.findLibrary(&quot;moshi&quot;).get())<br>            add(&quot;ksp&quot;, libs.findLibrary(&quot;moshi-codegen&quot;).get())<br>        }<br>    }<br>}</pre><p>Great, you’ve created your first convention plugin! But how do we <strong>use</strong> it in a module?</p><h4><strong>3. Register the Convention Plugin.</strong></h4><p>At first, we have to define the created convention plugin as a plugin in the libs.versions.toml</p><pre>[plugins]<br>moshi-convention = {id = &quot;com.test.convention.moshi&quot;} // this id could be everything</pre><p>You can consider everything as the id of your convention plugin</p><p>In the next step, we need to register the plugin to make it available for use.</p><p><strong>Register </strong>the MoshiConventionPlugin.kts in theconvention/build.gradle.kts</p><pre>gradlePlugin {<br>    plugins {<br>        register(&quot;MoshiConventionPlugin&quot;) {<br>            id = libs.plugins.moshi.convention.get().pluginId<br>            implementationClass = &quot;com.test.convention.MoshiConventionPlugin&quot;<br>        }<br>    }<br>}</pre><p>The important point in the level is that you have to write the <strong>exact correct root</strong> of the MoshiConventionPlugin.kts</p><h4><strong>4. Apply the Convention Plugin in Your Modules.</strong></h4><p>Finally, you can use the Moshi convention plugin in your modules, like the network module.</p><p>You must remove every plugin and dependencies related to the <strong>Moshi, </strong>and just replace the<strong> </strong>moshi-convention<strong> </strong>plugin.</p><p>Refactor the network/build.gradle.kts</p><pre>plugins {<br>    alias(libs.plugins.android.library)<br>    alias(libs.plugins.kotlin.android)<br>    alias(libs.plugins.hilt)<br>//    alias(libs.plugins.ksp)              // You must remove it<br>    alias(libs.plugins.moshi.convention)  // Add the moshi convention plugin<br>}<br><br>dependencies {<br>//    implementation(libs.moshi.converter)<br>//    implementation(libs.moshi)            // You must remove them<br>//    ksp(libs.moshi.codegen)<br>}</pre><p>Congratulations, you have done it :)</p><p>I’ll share more advanced convention plugins for build types and flavors soon. Stay tuned!</p><h4>→ Next Step: <a href="https://medium.com/@reza.zavareh7/gradle-convention-plugin-part-2-flavors-1a905d79b30b">Gradle Convention Plugin(Part 2, Flavors)</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0651a9fcaad" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>