<?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 Rupesh Urmaliya on Medium]]></title>
        <description><![CDATA[Stories by Rupesh Urmaliya on Medium]]></description>
        <link>https://medium.com/@rupeshurmaliya?source=rss-675629739a2c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bvNtU7nfTVDowlDWUVojUw.jpeg</url>
            <title>Stories by Rupesh Urmaliya on Medium</title>
            <link>https://medium.com/@rupeshurmaliya?source=rss-675629739a2c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 07:07:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rupeshurmaliya/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[Write a Custom Gradle Plugin Part 2]]></title>
            <link>https://medium.com/geekculture/write-a-custom-gradle-plugin-part-2-1732ac39ff96?source=rss-675629739a2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1732ac39ff96</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Rupesh Urmaliya]]></dc:creator>
            <pubDate>Mon, 11 Jan 2021 19:45:53 GMT</pubDate>
            <atom:updated>2021-05-08T22:30:23.543Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7D_xKISQXnS8OdMN.png" /><figcaption>Image Credit: <a href="https://gradle.org/">https://gradle.org/</a></figcaption></figure><h3>Write a Custom Gradle Plugin (Part 2)</h3><h4>Custom Gradle task with configuration</h4><p>In the <a href="https://rupeshurmaliya.medium.com/write-a-custom-gradle-plugin-part-1-22b37c3b7326">previous blog</a>, I have explained how to create a simple Gradle plugin. Here I’ll be discussing in more depth about Gradle task and how to configure parameters to the plugin during apply.</p><h4>Let’s start writing a custom Gradle task:</h4><p>Let’s take an example where I’ll be creating a resource(XML) file from <strong>JSON</strong> for an android app.</p><p>First, we’ll create a custom Gradle task and add it to the plugin.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20267e37c990e2121bba4154a2b65b29/href">https://medium.com/media/20267e37c990e2121bba4154a2b65b29/href</a></iframe><p>Now we’ll have to add this task to the plugin.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be2dacb1e6f5bb38ea288a3db862f367/href">https://medium.com/media/be2dacb1e6f5bb38ea288a3db862f367/href</a></iframe><p>Now trigger the <strong>uploadArchive</strong> task or execute from the terminal by using the below command:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0442dcff78312e8413576003b24dbd1d/href">https://medium.com/media/0442dcff78312e8413576003b24dbd1d/href</a></iframe><p>Now run the SimpleTask from the app, we will get the below output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jCxeB774m3kkAuKEzHE-iw.png" /></figure><p><em>Now let’s go one step further and read the JSON file and create the resource file from this task.</em></p><h4>Generate resource:</h4><p>First, let&#39;s create a resource.json file and place it inside the app directory (This is just for demo. You can specify any path).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b7e0a837090e9c229a83b883c53bca21/href">https://medium.com/media/b7e0a837090e9c229a83b883c53bca21/href</a></iframe><p>Now we’ll be parsing this <strong>JSON</strong> and converting it to a <strong>color resource file</strong>. In order to achieve this, we’ll need to make changes in our <strong>SimpleTask. </strong>Here we need two main things:</p><ol><li>Input file path (<strong>resource.json</strong>)</li><li>Output file path (<strong>resource.xml</strong>)</li></ol><p>Now our <strong>SimpleTask</strong> will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/24b45200f46102a818b3954f713ab153/href">https://medium.com/media/24b45200f46102a818b3954f713ab153/href</a></iframe><p>Now we’ll have to pass both the file&#39;s path to <strong>SimpleTask.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e3c1628ff824a9b2c7e3514a6454a970/href">https://medium.com/media/e3c1628ff824a9b2c7e3514a6454a970/href</a></iframe><p>Again export the plugin with new code changes and run the <strong>SimpleTask</strong> from the app. Now <strong>resource.xml</strong> will be added to <strong>app/src/main/res/values </strong>directory.</p><h4>Pass the config from app to plugin:</h4><p>To pass the file’s path to the plugin we’ll have to add an extension for the plugin. I have created a class <strong>PluginConfig</strong> for that and add as an extension to the plugin.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d68009e8b9da410da4e2363f1e627700/href">https://medium.com/media/d68009e8b9da410da4e2363f1e627700/href</a></iframe><p>Add as an extension to the plugin</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a39f6652c2c2aba02edd272416a01e2/href">https://medium.com/media/1a39f6652c2c2aba02edd272416a01e2/href</a></iframe><p>Now let&#39;s pass the plugin config from the app. For this add below lines of code in app’s build.gradle (module-level):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa67759b226bd8521e15764a72919084/href">https://medium.com/media/fa67759b226bd8521e15764a72919084/href</a></iframe><p>To retrieve this config in the plugin, our final <strong>SamplePlugin </strong>&amp;<strong> SimpleTask </strong>class will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e630ce555f88ebb29da6220977b380f/href">https://medium.com/media/0e630ce555f88ebb29da6220977b380f/href</a></iframe><p>The below lines of code is to retrieve the value of inputFile in the plugin which being pass from our app’s build.gradle (module-level).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f36b4f61ce11301a8c845623777bd673/href">https://medium.com/media/f36b4f61ce11301a8c845623777bd673/href</a></iframe><h4><strong>SimpleTask:</strong></h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/86bb307e038e4f85561921d1d984dfef/href">https://medium.com/media/86bb307e038e4f85561921d1d984dfef/href</a></iframe><h4><strong>Task grouping:</strong></h4><p>We can group all the tasks in place by using the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d359577193f48881d649022acd4fc6c7/href">https://medium.com/media/d359577193f48881d649022acd4fc6c7/href</a></iframe><p>Now if we check the app project the tasks will be grouped like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*YRsyVDbqx2f2dvk9GwOt_A.png" /></figure><p>Now if we run this task we’ll see the new files which will be added to the below path directory:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/851853c66f329ed4d49f651b6d0ccee5/href">https://medium.com/media/851853c66f329ed4d49f651b6d0ccee5/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bIsi5ZTxsBTUU93rgLpoCQ.png" /></figure><p><strong><em>Thanks for reading this. In the next part, I’ll be talking about Unit &amp; Functional testing of the plugin.</em></strong></p><h4>References:</h4><ul><li><a href="https://docs.gradle.org/current/userguide/custom_tasks.html">Developing Custom Gradle Task Types</a></li><li><a href="https://docs.gradle.org/current/userguide/custom_gradle_types.html">Developing Custom Gradle Types</a></li><li><a href="https://docs.gradle.org/current/userguide/more_about_tasks.html">Authoring Tasks</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1732ac39ff96" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/write-a-custom-gradle-plugin-part-2-1732ac39ff96">Write a Custom Gradle Plugin Part 2</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Write a Custom Gradle Plug-In for Your Android App (Part 1)]]></title>
            <link>https://medium.com/better-programming/write-a-custom-gradle-plugin-part-1-22b37c3b7326?source=rss-675629739a2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/22b37c3b7326</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Rupesh Urmaliya]]></dc:creator>
            <pubDate>Wed, 30 Dec 2020 06:18:42 GMT</pubDate>
            <atom:updated>2021-01-05T21:40:05.238Z</atom:updated>
            <content:encoded><![CDATA[<h3>Write a Custom Gradle Plugin for Your Android App (Part 1)</h3><h4>Empower your apps with a custom Gradle plugin</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ib0shjyBKuTK8TANmrprnw.png" /><figcaption>Image Credit: <a href="https://wallpaperaccess.com/">https://wallpaperaccess.com/</a></figcaption></figure><p>A Gradle plugin can be very powerful and do a lot of things. It can perform custom tasks and keep the app’s Gradle file clean and a lot more than that. This blog series covers how to write a simple custom Gradle plugin and unit test in Kotlin.</p><h3>Prerequisite</h3><p>To develop a custom Gradle plugin you need to have prior experience in Java/Kotlin, Gradle, and Android app development.</p><p><em>In this article, I will explain how to create a Gradle plugin with a simple output. I will add more details later in the series.</em></p><h4>Setup</h4><p>Here are the following steps to create a Gradle plugin:</p><ul><li>Download and install the IntelliJ IDE from this <a href="https://www.jetbrains.com/idea/download/">link</a>.</li><li>Open IDE and click on Gradle from the left side panel and select the Kotlin/JVM option, as mentioned below. Also, select the <strong>Kotlin DSL</strong> build script if you want your build.gradle file in Kotlin.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/0*zW7vmkN4KY6ts1pa" /><figcaption>Create a Gradle project</figcaption></figure><p>Enter the Gradle plugin name and specify the project directory and click on Finish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/735/0*o3l8NmMD6CI8HBG-" /><figcaption>Enter plugin name and location</figcaption></figure><p>Once the Gradle download is finished and the project is ready the directory will look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*Wkwbz1W9NTk9iTKN" /><figcaption>Project directory structure</figcaption></figure><p>Now add the dependencies to the project. Update build.gradle.kts like below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8671ab8c632c73b42b4aedaddf568df5/href">https://medium.com/media/8671ab8c632c73b42b4aedaddf568df5/href</a></iframe><h4>Now we have the setup ready. Let’s start writing some code:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*xIOuDtzYqAHFUi8J5DU3kA.png" /><figcaption>Create a package directory for the plugin</figcaption></figure><p>Let’s create a package for the plugin. Here we are writing the plugin in Kotlin. So we’ll be adding the package inside the Kotlin directory.</p><p>Create a class that will extend the Plugin&lt;Project&gt;. This is the entry point for the plugin. This will print the following message when we run this plugin from the app:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e4500fb1e404b5312a594fa76507f14/href">https://medium.com/media/2e4500fb1e404b5312a594fa76507f14/href</a></iframe><p>In the above code, I’m creating a task named SampleTask which will print Hello there!</p><h3>Packaging the Plugin</h3><p>There are three ways of packaging the plugin.</p><ul><li>Build script</li><li>buildSrc<strong> </strong>project</li><li>Standalone project</li></ul><p>In this sample, we will be creating a standalone project for this plugin. To know more about other ways, refer to the following <a href="https://docs.gradle.org/current/userguide/custom_plugins.html#sec:packaging_a_plugin">link</a>.</p><h3>Wiring the Plugin</h3><p>To run the plugin we need to provide the service locator by which Gradle will find its ID.</p><p>Note that this will be the same name as build.gradle.kts<strong><em> </em></strong>For this, add the following lines of code in build.gradle.kts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8121df481aa13ebd9ba6681bafac5116/href">https://medium.com/media/8121df481aa13ebd9ba6681bafac5116/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b2f741650137eec6de7deb960c9b6182/href">https://medium.com/media/b2f741650137eec6de7deb960c9b6182/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-sVRV4Uoh07dmjF_zbOCFg.png" /><figcaption>Add Service locator for Gradle plugin</figcaption></figure><p>Here we’re using the plugin as a standalone project. To add this plugin to the project we have to export this as a jar. For this, we’ll be exporting the plugin using a local directory path. For this include the below code in build.gradle.kts:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3b959b441c79d2446b22093fb8c9170c/href">https://medium.com/media/3b959b441c79d2446b22093fb8c9170c/href</a></iframe><p>The final build.gradle.kts will look like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3a723c73843ace2285186276951fab10/href">https://medium.com/media/3a723c73843ace2285186276951fab10/href</a></iframe><h3>Export the Plugin as a Jar</h3><p>To create the jar from plugin source code click on the right side of the panel and double click on uploadArchives. It will export the plugin at the given directory path. (<em>local_jar_path</em>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*cT8c2i_tnZCKANf3bXQhCw.png" /><figcaption>Export the plugin</figcaption></figure><h3>Integrate the Plugin in the App</h3><p>Add the plugin to root-level (project-level) build.gradle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/501e2e4d0179ac778b252a26ce2d369f/href">https://medium.com/media/501e2e4d0179ac778b252a26ce2d369f/href</a></iframe><p>Add plugin dependencies to module-level (app level) build.gradle:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7e2f084e442965ad83e06ecdc09a5e8/href">https://medium.com/media/a7e2f084e442965ad83e06ecdc09a5e8/href</a></iframe><h3><strong>We Are Done. Let&#39;s Test the Plugin</strong></h3><p>Once we have integrated the plugin in the app, we will be able to see the task in the app under the Gradle task tab:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*58ueMy6qXHi90Qp8F4DyEQ.png" /><figcaption>Custom Gradle task inside the app</figcaption></figure><p>To run this task we can just double-click on the task or use the Gradle command:</p><pre>./gradlew SampleTask</pre><h4><strong>Output</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/423/1*z7unHP_nMPfZ0Jq5bOLc2w.png" /><figcaption>Output of the task.</figcaption></figure><p><em>In the next part, I’ll be discussing the Gradle task in more depth, as well as how to add configuration for the plugin.</em></p><h4>Reference</h4><p><a href="https://docs.gradle.org/current/userguide/custom_plugins.html">Developing Custom Gradle Plugins</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22b37c3b7326" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/write-a-custom-gradle-plugin-part-1-22b37c3b7326">Write a Custom Gradle Plug-In for Your Android App (Part 1)</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>