0

In my application, I manage all Gradle stuff in buildSrc. One of them is buildTypes. I am able to access all the properties that buildTypes provide. However, I cannot access applicationVariants in buildSrc. Is there any way to do so?

Sample code block in buildSrc/BuildTypes.kt

internal object Debug : BuildTypeCreator {
    override val name = InternalBuildType.DEBUG

    override fun create(
        namedDomainObjectContainer: NamedDomainObjectContainer<BuildType>,
        project: Project,
        isLibrary: Boolean,
        closure: BuildType.() -> Unit
    ): BuildType {
        return namedDomainObjectContainer.maybeCreate(name).apply {
            if (isLibrary) {
                versionNameSuffix = "-dev-${project.gitSha}"
            } else {
                applicationIdSuffix = ".dev"
            }
            isTestCoverageEnabled = true
            isMinifyEnabled = false
            isDebuggable = true
            closure.invoke(this)
        }
    }
}

Sample code block in app.gradle.kts(which I want to achieve the same in buildSrc)

applicationVariants.all { -> **This is not accessible in buildSrc**
                if (buildType.name == getByName("release").name) {
                    outputs.all { output: BaseVariantOutput ->
                        val outputImpl = output as BaseVariantOutputImpl
                        outputImpl.outputFileName = "calendar-view.apk"
                        true
                    }
                }
            }

Thanks in advance.

nuhkoca
  • 1,777
  • 4
  • 20
  • 44

1 Answers1

0

OK, I solved it passing an argument domainObjectSet: DomainObjectSet<ApplicationVariant>

nuhkoca
  • 1,777
  • 4
  • 20
  • 44