Skip to content

Commit 0738087

Browse files
committed
Unify publish statement in CI config and brush up deploy script
1 parent dfe8788 commit 0738087

2 files changed

Lines changed: 13 additions & 88 deletions

File tree

‎.circleci/config.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ jobs:
122122
name: (Plugin) Build & Deploy
123123
command: |
124124
cd plugin
125-
./gradlew publishToSonatype closeAndReleaseSonatypeStagingRepository --stacktrace
125+
./gradlew publishAllPublicationsToSonatypeRepository closeAndReleaseStagingRepositories --stacktrace
126126
- store_artifacts:
127127
path: plugin/android-junit5/build/publications
128128
destination: plugin/publications/snapshots

‎build-logic/src/main/kotlin/Deployment.kt‎

Lines changed: 12 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import org.gradle.api.artifacts.ProjectDependency
99
import org.gradle.api.plugins.ExtensionAware
1010
import org.gradle.api.plugins.ExtraPropertiesExtension
1111
import org.gradle.api.publish.PublishingExtension
12+
import org.gradle.api.publish.internal.PublicationInternal
13+
import org.gradle.api.publish.maven.MavenArtifact
1214
import org.gradle.api.publish.maven.MavenPublication
1315
import org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication
1416
import org.gradle.api.tasks.SourceSet
@@ -19,6 +21,7 @@ import org.gradle.kotlin.dsl.maybeCreate
1921
import org.gradle.kotlin.dsl.register
2022
import org.gradle.kotlin.dsl.support.uppercaseFirstChar
2123
import org.gradle.kotlin.dsl.withGroovyBuilder
24+
import org.gradle.kotlin.dsl.withType
2225
import org.gradle.plugins.signing.Sign
2326
import org.gradle.plugins.signing.SigningExtension
2427
import 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
*/
352356
private 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

Comments
 (0)