Cannot configure base plugin in groovy-based build.gradle
kyhule opened this issue · 1 comments
I have a very old build that publishes android libraries that is still using groovy-based build.gradle
scripts. I need to update the build to publish multiple variants due to a business need to configure flavors. I am attempting to use the base plugin and configure it using AndroidMultiVariantLibrary
as documented here but I get an error when I try to pass the includedBuildTypeValues
and includedFlavorDimensionsAndValues
parameters.
Here is the configuration:
mavenPublishing {
configure(new AndroidMultiVariantLibrary(true, true, ["release"], ["flavor": ["foo", "bar"]]))
}
Here is the error:
Caused by: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.vanniktech.maven.publish.AndroidMultiVariantLibrary(Boolean, Boolean, ArrayList, LinkedHashMap)
Due to some unconventional complexities in the build scripts, I am unable to migrate to kotlin-based build.gradle.kts
at this time.
I tried a quick and dirty workaround by creating a maven-publish.gradle.kts
to configure it in kotlin and apply it to the bottom of my groovy-based build.gradle
but I ran into issues with it not being able to resolve the com.vanniktech.maven.publish
package even though the library is on the classpath.
Here is my maven-publish.gradle.kts
:
apply(plugin = "com.vanniktech.maven.publish.base")
extensions.getByType<com.vanniktech.maven.publish.MavenPublishBaseExtension>().apply {
pomFromGradleProperties()
configure(com.vanniktech.maven.publish.AndroidMultiVariantLibrary(includedBuildTypeValues = setOf("release"), includedFlavorDimensionsAndValues = mapOf("flavor" to setOf("foo", "bar"))))
}
Here is the error:
* What went wrong:
Script compilation errors:
Line 17: extensions.getByType<com.vanniktech.maven.publish.MavenPublishBaseExtension>().apply {
^ Unresolved reference: vanniktech
Alright, so I was able to get the configuration in groovy working by just casting to Set
and Map
like so:
mavenPublishing {
configure(new AndroidMultiVariantLibrary(true, true, ["release"] as Set, ["flavor": ["foo", "bar"] as Set ] as Map))
}
And found out the workaround didn't work because apply from buildscripts basically have their own classpath isolated from the build.
Closing this issue.