@@ -9,6 +9,8 @@ import org.gradle.api.artifacts.ProjectDependency
99import org.gradle.api.plugins.ExtensionAware
1010import org.gradle.api.plugins.ExtraPropertiesExtension
1111import org.gradle.api.publish.PublishingExtension
12+ import org.gradle.api.publish.internal.PublicationInternal
13+ import org.gradle.api.publish.maven.MavenArtifact
1214import org.gradle.api.publish.maven.MavenPublication
1315import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication
1416import org.gradle.api.tasks.SourceSet
@@ -19,6 +21,7 @@ import org.gradle.kotlin.dsl.maybeCreate
1921import org.gradle.kotlin.dsl.register
2022import org.gradle.kotlin.dsl.support.uppercaseFirstChar
2123import org.gradle.kotlin.dsl.withGroovyBuilder
24+ import org.gradle.kotlin.dsl.withType
2225import org.gradle.plugins.signing.Sign
2326import org.gradle.plugins.signing.SigningExtension
2427import java.io.File
@@ -115,10 +118,9 @@ private fun Project.configureAndroidDeployment(
115118 afterEvaluate {
116119 publishing {
117120 publications {
118- // Declare an empty 'main' publication and mark the actual variant publications
119- // as aliases to work around limitations of the Maven publication process.
120- // We write parts of the POM file ourselves to use distinct coordinates
121- // for project dependencies between instrumentation libraries
121+ // Declare an empty 'main' publication and mark the actual publication
122+ // for each variant as an 'alias'. This is done to work around limitations
123+ // of the Maven publication process
122124 maybeCreate<MavenPublication >(" main" )
123125
124126 register<MavenPublication >(junit.variant) {
@@ -130,8 +132,11 @@ private fun Project.configureAndroidDeployment(
130132 junit = junit
131133 )
132134
133- (this as DefaultMavenPublication ).isAlias = true
135+ (this as PublicationInternal < MavenArtifact > ).isAlias = true
134136
137+ // We have to write parts of the POM file ourselves, so that
138+ // project dependencies between instrumentation libraries use the correct
139+ // coordinates for each variant (e.g. "junit5" vs "junit6")
135140 configurePom(deployConfig)
136141 }
137142 }
@@ -169,7 +174,7 @@ private fun Project.configurePluginDeployment(
169174 }
170175
171176 // Connect signing task to the JAR produced by the artifact-producing task
172- tasks.withType( Sign :: class .java ).configureEach {
177+ tasks.withType< Sign >( ).configureEach {
173178 dependsOn(" assemble" )
174179 }
175180
@@ -346,35 +351,12 @@ private val Project.ext: ExtraPropertiesExtension
346351 get() = extensions.getByName(" ext" ) as ExtraPropertiesExtension
347352
348353/* *
349- * Allows us to retain the untyped Groovy API even in the stricter Kotlin context
350- * ("android.sourceSets.main.java.srcDirs")
354+ * Allows us to access certain APIs without access to the actual plugins. Brittle, but works.
351355 */
352356private class AndroidDsl (project : Project ) {
353357 private val delegate = project.extensions.getByName(" android" ) as ExtensionAware
354358
355- val sourceSets = SourceSetDsl (delegate)
356359 val publishing = PublishingDsl (delegate)
357- val productFlavors = ProductFlavorsDsl (delegate)
358-
359- class SourceSetDsl (android : ExtensionAware ) {
360- private val delegate = android.javaClass.getDeclaredMethod(" getSourceSets" )
361- .also { it.isAccessible = true }
362- .invoke(android) as NamedDomainObjectCollection <Any >
363-
364- val main = MainDsl (delegate)
365-
366- class MainDsl (sourceSets : NamedDomainObjectCollection <Any >) {
367- private val delegate = sourceSets.named(" main" ).get()
368-
369- val kotlin = KotlinDsl (delegate)
370-
371- class KotlinDsl (main : Any ) {
372- val srcDirs = main.javaClass
373- .getDeclaredMethod(" getKotlinDirectories" )
374- .invoke(main) as Set <File >
375- }
376- }
377- }
378360
379361 class PublishingDsl (android : ExtensionAware ) {
380362 private val delegate = android.javaClass.getDeclaredMethod(" getPublishing" )
@@ -390,10 +372,6 @@ private class AndroidDsl(project: Project) {
390372 })
391373 }
392374
393- fun multipleVariants (name : String , block : MultipleVariantsDsl .() -> Unit ) {
394- MultipleVariantsDsl (name, delegate).block()
395- }
396-
397375 class SingleVariantDsl (private val delegate : Any ) {
398376 fun withSourcesJar () {
399377 delegate.javaClass.declaredMethods
@@ -409,59 +387,6 @@ private class AndroidDsl(project: Project) {
409387 .invoke(delegate, true )
410388 }
411389 }
412-
413- class MultipleVariantsDsl (name : String , publishing : Any ) {
414- private lateinit var delegate: Any
415-
416- init {
417- publishing.javaClass
418- .getDeclaredMethod(" multipleVariants" , String ::class .java, Closure ::class .java)
419- .also { it.isAccessible = true }
420- .invoke(publishing, name, closureOf<Any > { delegate = this })
421- }
422-
423- fun allVariants () {
424- delegate.javaClass.declaredMethods
425- .first { it.name.startsWith(" allVariants" ) }
426- .also { it.isAccessible = true }
427- .invoke(delegate, true )
428- }
429-
430- fun includeBuildTypeValues (vararg buildTypes : String ) {
431- delegate.javaClass.declaredMethods
432- .first { it.name.startsWith(" setIncludedBuildTypes" ) }
433- .also { it.isAccessible = true }
434- .invoke(delegate, buildTypes.toSet())
435- }
436-
437- fun withSourcesJar () {
438- delegate.javaClass.declaredMethods
439- .first { it.name.startsWith(" withSourcesJar" ) }
440- .also { it.isAccessible = true }
441- .invoke(delegate, true )
442- }
443-
444- fun withJavadocJar () {
445- delegate.javaClass.declaredMethods
446- .first { it.name.startsWith(" withJavadocJar" ) }
447- .also { it.isAccessible = true }
448- .invoke(delegate, true )
449- }
450- }
451- }
452-
453- class ProductFlavorsDsl (android : ExtensionAware ) {
454- private val delegate = android.javaClass.getDeclaredMethod(" getProductFlavors" )
455- .also { it.isAccessible = true }
456- .invoke(android) as NamedDomainObjectCollection <Any >
457-
458- fun all (block : SupportedJUnit .() -> Unit ) {
459- delegate.all {
460- val flavorName = this .javaClass.getDeclaredMethod(" getName" ).invoke(this ) as String
461- val junit = SupportedJUnit .fromVariant(flavorName)
462- block(junit)
463- }
464- }
465390 }
466391}
467392
0 commit comments