All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.avito.test.gradle.module.KotlinModule.kt Maven / Gradle / Ivy

Go to download

Collection of infrastructure libraries and gradle plugins of Avito Android project

There is a newer version: 2024.32
Show newest version
package com.avito.test.gradle.module

import com.avito.test.gradle.dependencies.GradleDependency
import com.avito.test.gradle.dir
import com.avito.test.gradle.files.build_gradle
import com.avito.test.gradle.files.build_gradle_kts
import com.avito.test.gradle.kotlinClass
import com.avito.test.gradle.kotlinVersion
import com.avito.test.gradle.module
import com.avito.test.gradle.plugin.PluginsSpec
import com.avito.test.gradle.plugin.plugins
import java.io.File

public class KotlinModule(
    override val name: String,
    public val packageName: String = "com.$name",
    override val plugins: PluginsSpec = PluginsSpec(),
    override val buildGradleExtra: String = "",
    override val modules: List = emptyList(),
    override val dependencies: Set = emptySet(),
    override val useKts: Boolean = false,
    private val mutator: File.() -> Unit = {}
) : Module {

    override fun generateIn(file: File) {
        file.module(name) {

            val buildGradleContent = """
                |${plugins()}
                |
                |$buildGradleExtra
                |
                |dependencies {
                |   ${dependencies.joinToString(separator = "\n\t", transform = { it.getScriptRepresentation() })}
                |   implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
                |}
                """.trimMargin()

            if (useKts) {
                build_gradle_kts {
                    writeText(buildGradleContent)
                }
            } else {
                build_gradle {
                    writeText(buildGradleContent)
                }
            }

            dir("src/main") {
                dir("kotlin") {
                    kotlinClass("SomeClass", packageName)
                }
            }
            this.mutator()
        }
    }

    private fun plugins(): PluginsSpec =
        plugins {
            id("kotlin")
        }.plus(plugins)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy