Search code examples
androidkotlingroovygradle-kotlin-dsl

Migrating from build.gradle to build.gradle.kts having issue with some code snippets


Kotlin 1.4.10
AS 4.1

I have a build.gradle (app) that I am migrating to build.gradle.kts. The only 2 code snippets I haven't been able to change is the following.

Just wondering what the following should be in build.gradle.kts

productFlavors {
    project.android.buildTypes.all { buildType ->
        buildType.javaCompileOptions.annotationProcessorOptions.arguments =
            [
                    enableParallelEpoxyProcessing: "true"
            ]
    }

    variantFilter { variant ->
        def names = variant.flavors*.name

        if ((names.contains("sit") && variant.buildType.name == "release")
                || (names.contains("staging") && variant.buildType.name == "release")) {
            variant.ignore = true
        }
    }
}

Many thanks for any suggestions,


Solution

  • I thinks it should be like this :

        productFlavors {
            project.android.buildTypes.forEach { buildType ->
                buildType.javaCompileOptions {
                    annotationProcessorOptions {
                        argument("enableParallelEpoxyProcessing", "true")
                    }
                }
            }
    
            variantFilter {
                val names = this.flavors.map { name }
                if ((names.contains("sit") && this.buildType.name == "release") ||
     (names.contains("staging") && this.buildType.name == "release")) {
                    this.ignore = true
                }
            }
        }