<?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 Umut TEKE on Medium]]></title>
        <description><![CDATA[Stories by Umut TEKE on Medium]]></description>
        <link>https://medium.com/@umut.teke?source=rss-d171f9befe86------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*_LOfzXsgL2BXSQOfX7aUqA.png</url>
            <title>Stories by Umut TEKE on Medium</title>
            <link>https://medium.com/@umut.teke?source=rss-d171f9befe86------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 13:39:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@umut.teke/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[Lighten MVI architecture: Delegate responsibilities to new components]]></title>
            <link>https://proandroiddev.com/lighten-mvi-architecture-delegate-responsibilities-to-new-components-7ea27ea54021?source=rss-d171f9befe86------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ea27ea54021</guid>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[mvi]]></category>
            <category><![CDATA[model-view-intent]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Umut TEKE]]></dc:creator>
            <pubDate>Fri, 15 Sep 2023 14:45:42 GMT</pubDate>
            <atom:updated>2023-09-15T14:45:42.864Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*F6BoKK7ibVWv2L3MqJL8NQ.png" /><figcaption>Image from <a href="https://codendot.com/mobile-application-development-115">Codendot</a></figcaption></figure><p>It’s been a while since I have been working on MVI to improve the MVVM pattern to manage a single immutable view state in the reactive flow architecture. In that way, the features are explicit, seem more understandable, and are straightforward to maintain, debug, and test. I considered testing the view state changes, was partially testing the UI in a world without QA engineers, and we have less time to write UI tests.<br>It started with RxJava to move step by step to coroutines and Flow.<br>Now, designing Compose views makes more sense to keep MVI as the primary architectural pattern for state management.<br>Over time, we faced complexities in making apps scalable and maintainable.<br>I will share an option to reduce MVI complexity from basic implementation to new component delegation.</p><h3>The Basics of MVI</h3><p>Model View Intent (MVI) is an architectural presentation pattern inspired by the <a href="https://redux.js.org/usage/">Redux</a> circular pattern. It offers a reactive and predictable approach to manage state and handle user intents to interact with the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGpWeMHJGX-x3aS_2vCEHA.jpeg" /><figcaption>MVI unidirectional flow</figcaption></figure><p>The <strong>Model</strong> represents the single state and the business model. It manages the data and responds to user intents to produce a new state. The Model ensures that the state remains immutable and processes user interactions.</p><p>The <strong>View</strong> is responsible for rendering the user interface and displaying the current view state. In MVI, the View is passive and only observes the view state changes from the Model. It does not contain business logic and focuses solely on displaying information to the user.</p><p>The <strong>Intent</strong> represents user actions that trigger state changes. These could be actions like button clicks, text input, or any other user interaction. Intents are dispatched from the View to the Model, indicating the user’s desired action.</p><p>The MVI pattern promotes immutability, ensuring the application&#39;s state remains consistent and predictable. Using MVI, developers can build apps that are easier to test, maintain, and scale.<br>It’s gaining popularity due to its clear separation of concerns and its ability to handle complex state management in a reactive and maintainable way.</p><p>In the Android context, migrating an existing MVVM to MVI is simple by grouping the states into one single. It fits nicely with Compose to manage a feature state. Moreover, debugging a single state helps monitor the property changes and understand the app&#39;s behavior.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bHIgEr8obmAMkzulCWFelA.jpeg" /><figcaption>MVI concrete flow</figcaption></figure><p>Here is an example of MVI implementation into the UserListViewModel to display a list with some item interaction on the screen.<br>The View interacts with it to process an Action. We assume using Action rather than Intent to avoid confusing Android-specific terms.<br>It exposes two flows. Internally, the first is a cold flow of ViewState typed as StateFlow to get the current state, and the second is a hot flow of Event as Channel. Sometimes, developers prefer using the side effect term instead.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35f96dc336ebce87c436d8e4a6843f2d/href">https://medium.com/media/35f96dc336ebce87c436d8e4a6843f2d/href</a></iframe><h3>Sealed or flat state: How to define the view state?</h3><p>A sealed state is a complex approach to representing the screen state. It allows you to create a closed set of subclasses holding different states.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6419344c8bc3004d356585c914720190/href">https://medium.com/media/6419344c8bc3004d356585c914720190/href</a></iframe><p>A sealed interface can benefit features with more complex state structures, allowing for better organization and type safety when handling different states.<br>However, the sealed structure requires good substate switching by managing a cache to make the data more accessible and prevent over-fetching.</p><p>A flat state is a straightforward representation by using a data class. It contains all the necessary fields to represent the current state of the screen in a balanced and hierarchical structure.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26d355c2983d34f1bff5794805a77829/href">https://medium.com/media/26d355c2983d34f1bff5794805a77829/href</a></iframe><p>A flat state is easy to understand and update, especially for more minor features or those with relatively simple state requirements.<br>Unlike checking the sealed substates, you can manage flags manipulated by the view by changing the behavioral properties. Then, you keep the content data you could immediately display and fetch over.</p><h3>ViewModel complexity &amp; heaviness issues</h3><p>The Model component, here the ViewModel, is responsible for processing the actions by calling the logic, the use cases or the repositories, and emitting state changes or events.<br>The snippet above shows a partial implementation for one of the actions; it already gets over a hundred lines of code. With much more action, the UserListViewModel becomes challenging to manage and maintain. <br>The first documentation is the source code. The ViewModel is expected to be concise and explicit. It is the same for the test classes that could be heavier.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5bc7f84476b0376e2d293dbaa78abf9b/href">https://medium.com/media/5bc7f84476b0376e2d293dbaa78abf9b/href</a></iframe><p>To solve the issues, the ViewModel has to be lightened by delegating the responsibilities to new components step by step.</p><h3>Use reducers for UI mutations</h3><p>Let’s first introduce the Reducer pattern. It is initially a function that takes the current state and an action as input and returns a new state in the Redux architecture. The reducer updates the state based on the user’s actions and the model’s updates.<br>Here, the usage we expect is a bit different. The reducer is used for transformation, which takes the current state and a mutation to get the expected transformation.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/870a831c10593c535b78f488d290c328/href">https://medium.com/media/870a831c10593c535b78f488d290c328/href</a></iframe><p>Mutation is an internal action that identifies the transformation. It could contain properties representing flags or models retrieved by the use case required for the transformation. It’s different from the partial state developers commonly used to update a part of the view state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cff81523d8987f8f88d6c4002de69bb3/href">https://medium.com/media/cff81523d8987f8f88d6c4002de69bb3/href</a></iframe><p>DefaultReducer transforms the current view state differently by mutation. It reduces the current state by copying into a new one and mapping the models from Mutation. Here, the reducer takes the Android Resources to format texts, to get drawables or colors.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/296c7216a9fd3f080afd7efc873f83c2/href">https://medium.com/media/296c7216a9fd3f080afd7efc873f83c2/href</a></iframe><p>Then, the ViewModel can manage one or many reducers. As a best practice, scoping the reducers is recommended. <br>The mutation has to be handled by one reducer, but there is no way to restrict it. <br>The ViewModel was doing the transformation, henceforth invoking the reducers with a mutation to update the current state.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e596b22587697ced7ae05e6bb91dd760/href">https://medium.com/media/e596b22587697ced7ae05e6bb91dd760/href</a></iframe><p>Having delegated the transformation, the next big step is moving the logic out.</p><h3>Manage logic in action processors</h3><p>ActionProcessor is a new component to manage the actions to return a flow of pair of Mutation &amp; Event. <br>Why a flow? The processor could emit one or many values. The value can be a mutation, an event, or both. This is why they are nullable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa03214dfc8b0b72452432f4d89f226b/href">https://medium.com/media/fa03214dfc8b0b72452432f4d89f226b/href</a></iframe><p>The partial implementation above, DefaultActionProcessor, gives an example of the Load action to get the user list from the given repository.<br>Following the happy path, it emits ShowLoader and then ShowContent with the list of UserDataModel.<br>Besides calling the use cases or the repositories, the action processor can manage other middle components like trackers, loggers, analytics, etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e156188495cb80e0d7f24fc12fad4029/href">https://medium.com/media/e156188495cb80e0d7f24fc12fad4029/href</a></iframe><h3>Combine action processors and reducers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Vyzl9O9C3wxxcZRSrvxkw.jpeg" /></figure><p>After moving the logic into action processors, the ViewModel now collects the mutations &amp; the events emitted by the action processors. The reducers reduce the mutations, and the event is emitted again to the View.<br>Everything has been delegated to the new components. The ViewModel now has simple responsibilities, which are invoking action processors and reduce the mutations collected from them via the reducers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/081bb6a7c3a6d121169965590f5d90dd/href">https://medium.com/media/081bb6a7c3a6d121169965590f5d90dd/href</a></iframe><p>In addition, it’s essential to realize that components can be used together or as individual parts. <br>It’s almost done. We need a reusable pattern to make these components easy to implement. <br>Using base classes was very common to reduce duplication and reuse shared code. The concern is that only one class inheritance forces us to create a generic base ViewModel that can also handle other things not related to this, then breaking the single responsibility principle.</p><p>Let’s create a new Model generic class to export the action processing and view state reducing responsibilities from the ViewModel.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/891a9f341ad639aac5ee61b9eeb9326d/href">https://medium.com/media/891a9f341ad639aac5ee61b9eeb9326d/href</a></iframe><p>The Model class requires a CoroutineScope to launch coroutines calls, and<br>a MutableStateFlow of ViewState and the Event Channel .<br>Why inject those last two parameters? Why not have them as private properties like in the ViewModel?<br>We create ModelProperty as ReadOnlyProperty to get the instance by <a href="https://kotlinlang.org/docs/delegated-properties.html">property delegation</a>. It’s read only; we need to inject the properties we update.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c8bfee5c177131223ebfb8937f4c907/href">https://medium.com/media/4c8bfee5c177131223ebfb8937f4c907/href</a></iframe><p>Finally, UserListViewModel new implementation is lighter through the delegate.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73db45aa8043f59eb9c288d7e4895ca6/href">https://medium.com/media/73db45aa8043f59eb9c288d7e4895ca6/href</a></iframe><h3>Conclusion</h3><p>It’s crucial to appreciate the approach suggested is just one of many options for extending and relaxing the MVI. The main goal is to lighten complex ViewModels.<br>Reducer and ActionProcessor components are not mandatory and can be implemented independently. Keep the ViewModel simple and extend it as much as you need. <br>This approach is open to discussion, and I would like your feedback.<br>You can find the project on Github <a href="https://github.com/uteke/contact-book">here</a>.</p><p><a href="https://github.com/uteke/contact-book.git">GitHub - uteke/contact-book: Complete Android project to share best practices</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ea27ea54021" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/lighten-mvi-architecture-delegate-responsibilities-to-new-components-7ea27ea54021">Lighten MVI architecture: Delegate responsibilities to new components</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gradle Kotlin convention plugins for modularized structure — Shared build logic]]></title>
            <link>https://proandroiddev.com/gradle-kotlin-convention-plugins-for-modularized-structure-shared-build-logic-e740e1f07e88?source=rss-d171f9befe86------2</link>
            <guid isPermaLink="false">https://medium.com/p/e740e1f07e88</guid>
            <category><![CDATA[modularization]]></category>
            <category><![CDATA[gradle-kotlin-dsl]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[plugins]]></category>
            <dc:creator><![CDATA[Umut TEKE]]></dc:creator>
            <pubDate>Mon, 29 May 2023 18:21:45 GMT</pubDate>
            <atom:updated>2023-05-29T18:21:45.541Z</atom:updated>
            <content:encoded><![CDATA[<h3>Gradle Kotlin convention plugins for modularized structure — Shared build logic</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*J4UsuqB0jHXz6ODMbf826g.png" /><figcaption>Image from<a href="https://blog.jetbrains.com/kotlin/2020/02/improved-gradle-kts-ide-support/"> Jetbrains blog article</a></figcaption></figure><p>Many of us have faced Groovy difficulties and used to convert it to Kotlin DSL. Then, as Android engineers, working on a project entirely written in Kotlin is pure joy.</p><p>We assume going on a feature-based modularized app structure applying the version catalog feature. We would adequately manage the build logic to make it centralized and reusable by the modules.<br>Here are the steps to facilitate your Gradle build configurations into a centralized build logic by creating your convention plugin scripts.</p><p>The typical way we all used was to place the custom scripts into the default buildSrc module. Previously, buildSrc implementation was not recommended because of invalidating the build cache and synchronizing the whole project with every change to the dependencies.<br>It’s now treated as an included build in <a href="https://github.com/gradle/gradle/pull/22540">Gradle 8</a>.</p><h3>Project level declaration</h3><p>In the project settings script, we move the configuration scripts into a build-logic composite build module.<br>The first pluginManagement block ensures Gradle uses suitable repositories for the plugins. We include our new module in the build and specify explicitly the repositories we need.<br>Another key element is the mode in the <a href="https://docs.gradle.org/7.4.2/userguide/dependency_management.html#sub:centralized-repository-declaration">centralized dependency declarations</a> that you would declare to enforce Gradle always to get the correct dependencies regarding the resolution mode. In this example, we would use the repositories stated in the project settings.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/815d5163a143c940976b93b0f2d6793c/href">https://medium.com/media/815d5163a143c940976b93b0f2d6793c/href</a></iframe><h3>Shared logic composite module</h3><p>We start the new composite module by enabling the version catalog feature in the settings script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b5574a2ed504c41b20b7f7d74374d7bb/href">https://medium.com/media/b5574a2ed504c41b20b7f7d74374d7bb/href</a></iframe><p>Now, we define our new module as a Kotlin script by enabling the Kotlin DSL and forcing the <a href="https://plugins.gradle.org/plugin/org.gradle.kotlin.kotlin-dsl.precompiled-script-plugins">precompiled script plugins</a> to make it part of the Kotlin source set like any other class.<br>Henceforth, the composite module as part of the project build is responsible for the configuration, which we usually do in the project-level Gradle build script. We move there the Gradle-specific declarations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/916e3c3eeea5e2b70861dee10ce80e46/href">https://medium.com/media/916e3c3eeea5e2b70861dee10ce80e46/href</a></iframe><h3>Type-based conventions</h3><p>In a feature-based modularized app structure, we have the main app module, the feature modules, and the shared modules for some reusable logic or data, for example.</p><p>The main convention plugins we identify :</p><ul><li>Kotlin library convention</li><li>Android library convention</li><li>Android composable library convention</li></ul><h4>Kotlin library convention</h4><p>Kotlin library convention is a plugin we usually use to declare some APIs or to share some logic. It is an overridden Java library where we target the JDK version.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cfcc42f6d994f1496b3c21d9bedd2bbe/href">https://medium.com/media/cfcc42f6d994f1496b3c21d9bedd2bbe/href</a></iframe><h4>Kotlin Android library convention</h4><p>Kotlin Android library convention is applied by the feature modules with <a href="https://developer.android.com/topic/libraries/view-binding">ViewBinding</a> feature activated by default.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/61e0c4e53244267b81a50bb2f4d840ba/href">https://medium.com/media/61e0c4e53244267b81a50bb2f4d840ba/href</a></iframe><h4>Kotlin Android composable library convention</h4><p>It is an extension of the previous library convention with the Jetpack Compose-related declarations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ddf5a15b712dc44b83cf99bf11a4f31/href">https://medium.com/media/2ddf5a15b712dc44b83cf99bf11a4f31/href</a></iframe><p>When we create a new module, it is much easier to define the build script by applying the convention plugins and the additional dependencies.<br>We could also consider applying the composite module to another project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35bdac703415b5abf36e5ac0efa5f331/href">https://medium.com/media/35bdac703415b5abf36e5ac0efa5f331/href</a></iframe><h3>Conclusion</h3><p>In conclusion, modularization is our main concern for the ever-growing projects to solve many problems we can enumerate: codebase size, scalability, readability, code quality, code duplication, etc.<br>We usually and naturally split the project into feature-oriented modules by isolating the feature code.<br>Google Android team has also recently published a <a href="https://developer.android.com/topic/modularization">guide to app modularization</a> with the same approach.</p><p>There are some constraining issues related to Version Catalog.<br>The libraries are not directly accessible, and we need to create some extension functions to solve it.<br>And the plugins are not recognized in the plugins block. The <a href="https://github.com/gradle/gradle/issues/22797">issue</a> seems fixed in Gradle 8.</p><p>You can find all of the source code in my Github conventions repository <a href="https://github.com/uteke/gradle-kotlin-convention-plugins">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e740e1f07e88" width="1" height="1" alt=""><hr><p><a href="https://proandroiddev.com/gradle-kotlin-convention-plugins-for-modularized-structure-shared-build-logic-e740e1f07e88">Gradle Kotlin convention plugins for modularized structure — Shared build logic</a> was originally published in <a href="https://proandroiddev.com/">ProAndroidDev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Better dependencies management with Kotlin DSL]]></title>
            <link>https://medium.com/frichtitech/better-dependencies-management-with-kotlin-dsl-553ce80c144e?source=rss-d171f9befe86------2</link>
            <guid isPermaLink="false">https://medium.com/p/553ce80c144e</guid>
            <category><![CDATA[gradle]]></category>
            <category><![CDATA[dsl]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[gradle-kotlin-dsl]]></category>
            <dc:creator><![CDATA[Umut TEKE]]></dc:creator>
            <pubDate>Tue, 23 Mar 2021 10:18:27 GMT</pubDate>
            <atom:updated>2021-03-23T10:18:27.240Z</atom:updated>
            <content:encoded><![CDATA[<h3>Better dependencies management with Kotlin DSL — Scale your configuration</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*LK-QTWoFYe_JnG1FV2givg.png" /></figure><p>Let’s see in this article, how to migrate to <a href="https://docs.gradle.org/current/userguide/kotlin_dsl.html">Gradle Kotlin DSL</a> to properly centralize your <a href="https://gradle.org/">Gradle</a> dependencies.<br>DSL means <a href="https://www.jetbrains.com/mps/concepts/domain-specific-languages/">Domain-Specific Language</a> targeting to a particular kind of problem, rather than a general purpose language like Java aimed at any kind of software problem.<br>Thereby Kotlin DSL is a language dedicated to Gradle to build configuration in Kotlin instead of Groovy.</p><h4>Why Gradle Kotlin DSL will benefit you ?</h4><p>When you start developing in Kotlin, you could write your build configuration scripts in Kotlin. Groovy is not easy to manage.<br>In addition to the language, one of the main interests of this new syntax is the auto-completion offered by statically typed Kotlin. Unlike Groovy, which is dynamic, Android Studio struggles to set up the methods and parameters for you and reports input errors.<br>In order to take advantage of the new improvements made since version 3 of the Android plugin for Gradle, Google advises us to divide our projects into modules when our functional scope is sufficiently provided. This means that you have to manage the Gradle configurations in each module and keep control of the dependencies versions.</p><h4>How do we usually start managing our dependencies ?</h4><p>You probably started by adding dependencies manually which requires a lot of manual changes to updates libraries version.<br>Simple example of two modules <strong>feature_a</strong> and <strong>feature_b</strong> having some common dependencies.</p><pre><strong>feature_a/build.gradle</strong></pre><pre>dependencies {<br>   implementation &quot;androidx.appcompat:appcompat:1.2.0&quot;<br>   implementation &quot;androidx.constraintlayout:constraintlayout:<a href="https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout/2.0.1">2.0.1</a>&quot;<br>   implementation &quot;androidx.recyclerview:recyclerview:1.1.0&quot;<br>   implementation &quot;com.airbnb.android:lottie:<a href="https://mvnrepository.com/artifact/com.airbnb.android/lottie/3.4.4">3.4.4</a>&quot;<br>}</pre><pre><strong><br>feature_b/build.gradle</strong></pre><pre>dependencies {   <br>   implementation &quot;androidx.appcompat:appcompat:1.2.0&quot;<br>   implementation &quot;androidx.fragment:fragment-ktx:1.1.0&quot;<br>   implementation &quot;androidx.transition:transition:<a href="https://mvnrepository.com/artifact/androidx.transition/transition/1.3.1">1.3.1</a>&quot;<br>   implementation &quot;com.airbnb.android:lottie:<a href="https://mvnrepository.com/artifact/com.airbnb.android/lottie/3.4.4">3.4.4</a>&quot;<br>}</pre><h4>How to ensure that common dependencies have the same version ?</h4><p>Google recommends to set <a href="https://developer.android.com/studio/build/gradle-tips.html#configure-project-wide-properties">extra properties</a> in root <strong>build.gradle</strong> file for version centralization.<br>But we go further and go through the Kotlin configuration for Gradle which is more readable and friendly.</p><p>First we update root Gradle build configuration script to get kotlin plugin.</p><pre><strong>build.gradle.kts</strong></pre><pre>buildscript <strong>{<br>    </strong><em>repositories </em><strong>{<br>        </strong>google()<br>        jcenter()<br>    <strong>}<br>    </strong>dependencies <strong>{<br>        </strong><em>classpath</em>(&quot;com.android.tools.build:gradle:4.0.1&quot;)<br>        <strong><em>classpath</em>(&quot;org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21&quot;)</strong><br>    <strong>}<br>}<br><br></strong>allprojects <strong>{<br>    </strong><em>repositories </em><strong>{<br>        </strong>google()<br>        jcenter()<br>    <strong>}<br>}<br><br></strong><em>tasks</em>.<em>register</em>(&quot;clean&quot;, Delete::class)<strong>{<br>    </strong>delete(<em>rootProject</em>.<em>buildDir</em>)<br><strong>}</strong></pre><p>Next, we create a new <strong>buildSrc</strong> module. This module is a Gradle feature allowing you to define tasks and tool kits to write build scripts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*FJtufiBYZ2lNawVfQRilPQ.png" /></figure><p>We start to add a build configuration script file like any module.<br>However, this script is in Kotlin (with <strong>.kts</strong> extension for Kotlin Script) and we apply the Kotlin DSL plugin to it as shown below.</p><pre><strong>buildSrc/build.gradle.kts</strong></pre><pre>plugins {<br><strong>    `kotlin-dsl`<br></strong>}<br><br>repositories {<br>    jcenter()<br>}</pre><p>Next step, we create our Kotlin properties in a file that we could name <strong>Dependencies.kt</strong> to declare our dependencies and our versions.</p><pre><strong>buildSrc/src/main/kotlin/Dependencies.kt</strong></pre><pre>object Versions {<br>   const val appCompat = &quot;1.2.0&quot;<br>   const val constraintLayout = &quot;<a href="https://mvnrepository.com/artifact/androidx.constraintlayout/constraintlayout/2.0.1">2.0.1</a>&quot;<br>   const val recyclerView = &quot;1.1.0&quot;<br>   const val transition = &quot;<a href="https://mvnrepository.com/artifact/androidx.transition/transition/1.3.1">1.3.1</a>&quot;<br>   const val lottie = &quot;<a href="https://mvnrepository.com/artifact/com.airbnb.android/lottie/3.4.4">3.4.4</a>&quot;<br>}<br><br>object Libraries {   <br>   val androidx = AndroidX<br>   const val lottie = &quot;com.airbnb.android:lottie:${Versions.lottie}&quot;<br>}<br><br>object AndroidX {<br>   const val appCompat = &quot;androidx.appcompat:appcompat:${Versions.appCompat}&quot;<br>   const val constraintLayout = &quot;androidx.constraintlayout:constraintlayout:${Versions.constraintLayout}&quot;<br>   const val recyclerView = &quot;androidx.recyclerview:recyclerview:${Versions.recyclerView}&quot;<br>   const val transition = &quot;androidx.transition:transition:${Versions.transition}&quot;<br>}</pre><p>The dependencies are more readable and enable centralization for better control.<br>Finally, start a Gradle synchronization. We can now access and apply our dependencies to the configuration scripts to the previous modules.</p><pre><strong>feature_a/build.gradle.kts</strong></pre><pre>dependencies {   <br>   implementation(Libraries.androidX.appCompat)<br>   implementation(Libraries.androidX.constraintLayout)<br>   implementation(Libraries.androidX.recyclerView)<br>   implementation(Libraries.lottie)<br>}</pre><pre><strong>feature_b/build.gradle.kts</strong></pre><pre>dependencies {<br>   implementation(Libraries.androidX.appCompat)<br>   implementation(Libraries.androidX.fragment)<br>   implementation(Libraries.androidX.transition)<br>   implementation(Libraries.lottie)<br>}</pre><p>See below an example of autocompletion displayed from Kotlin DSL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iXJbJLGJtAIOqQ6qHUNtrw.png" /></figure><p>Note that the transformation of your configuration scripts is not required. You can continue using Groovy combined with Kotlin DSL.</p><p>In conclusion, the DSL allows you to master your dependencies and have centralized management when your project takes on a larger scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=553ce80c144e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/frichtitech/better-dependencies-management-with-kotlin-dsl-553ce80c144e">Better dependencies management with Kotlin DSL</a> was originally published in <a href="https://medium.com/frichtitech">FrichtiTech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>