Skip to content

Commit 7520c6f

Browse files
authored
Create a separate integration repo per project
Since the integration repo is technically a build output of the plugin project, it should live under the plugin's project's build directory and not the build directory of the root project
1 parent 3827c34 commit 7520c6f

File tree

3 files changed

+46
-22
lines changed

3 files changed

+46
-22
lines changed

integration-tests/build.gradle.kts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ jacoco {
3131
tasks {
3232
test {
3333
systemProperty("version", "$version")
34-
systemProperty("testkit-integration-repo", rootProject.layout.buildDirectory.dir("integration-repo").get().asFile.path)
34+
systemProperty("testkit-integration-repo", layout.buildDirectory.dir("testkit-integration-repo").get().asFile.path)
35+
36+
reports {
37+
junitXml.required = true
38+
}
3539
}
3640
}
3741

3842
configureIntegrationPublishing("testRuntimeClasspath")
39-
publishOnlyIf { _, repo -> repo == RepositoryDescriptor.INTEGRATION }
43+
publishOnlyIf { _, repo -> repo.isIntegration() }
4044

4145
tasks.withType<PublishTask> {
4246
enabled = false

shared-build-logic/src/main/kotlin/com/toasttab/gradle/testkit/shared/IntegrationPublishing.kt

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,31 @@ import org.gradle.kotlin.dsl.named
3030
import org.gradle.kotlin.dsl.register
3131
import org.gradle.kotlin.dsl.withType
3232
import org.gradle.plugin.devel.GradlePluginDevelopmentExtension
33+
import java.net.URI
3334

3435
sealed interface RepositoryDescriptor {
35-
object MavenLocal : RepositoryDescriptor
36-
data class MavenRemote(val name: String) : RepositoryDescriptor
36+
fun isIntegration(): Boolean
37+
38+
object MavenLocal : RepositoryDescriptor {
39+
override fun isIntegration() = false
40+
}
41+
42+
class MavenRemote(val name: String, val url: URI) : RepositoryDescriptor {
43+
override fun isIntegration() = name.startsWith(INTEGRATION_REPO_NAME_PREFIX)
44+
45+
val capitalizedName by lazy { name.simpleCapitalize() }
46+
}
3747

3848
companion object {
39-
const val INTEGRATION_REPO_NAME = "integration"
40-
val INTEGRATION = MavenRemote(INTEGRATION_REPO_NAME)
49+
const val INTEGRATION_REPO_NAME_PREFIX = "testkitIntegrationFor"
4150
}
4251
}
4352

4453
data class PublicationDescriptor(val name: String) {
4554
fun isPlugin() = name.endsWith("PluginMarkerMaven")
4655

4756
companion object {
48-
const val INTEGRATION_PUBLICATION_NAME = "integration"
57+
const val INTEGRATION_PUBLICATION_NAME = "testkitIntegration"
4958
val INTEGRATION = PublicationDescriptor(INTEGRATION_PUBLICATION_NAME)
5059
}
5160
}
@@ -59,17 +68,26 @@ fun Project.publishOnlyIf(predicate: (PublicationDescriptor, RepositoryDescripto
5968

6069
project.tasks.withType<PublishToMavenRepository> {
6170
onlyIf {
62-
predicate(PublicationDescriptor(publication.name), RepositoryDescriptor.MavenRemote(repository.name))
71+
predicate(PublicationDescriptor(publication.name), RepositoryDescriptor.MavenRemote(repository.name, repository.url))
6372
}
6473
}
6574
}
6675

67-
val Project.integrationRepo get() = rootProject.layout.buildDirectory.dir("integration-repo").get().asFile.path
76+
fun Project.integrationDirectory() = layout.buildDirectory.dir("testkit-integration-repo").get().asFile
6877

6978
fun Project.configureIntegrationPublishing(
7079
configuration: String = "runtimeClasspath"
7180
) {
72-
val repo = integrationRepo
81+
val repo = RepositoryDescriptor.MavenRemote(
82+
name = RepositoryDescriptor.INTEGRATION_REPO_NAME_PREFIX + path.split(Regex("\\W+")).mapIndexed { i, s ->
83+
if (i == 0) {
84+
s
85+
} else {
86+
s.simpleCapitalize()
87+
}
88+
}.joinToString(separator = ""),
89+
url = integrationDirectory().toURI()
90+
)
7391

7492
afterEvaluate {
7593
val coverage = project.coverage()
@@ -87,11 +105,11 @@ fun Project.configureIntegrationPublishing(
87105
}
88106

89107
tasks.named("test") {
90-
dependsOn("publishIntegrationPublicationToIntegrationRepository")
108+
dependsOn("publishTestkitIntegrationPublicationTo${repo.capitalizedName}Repository")
91109
}
92110
}
93111

94-
private fun Project.configureIntegrationPublishingForDependency(project: Project, repo: Any, coverage: CoverageConfiguration) {
112+
private fun Project.configureIntegrationPublishingForDependency(project: Project, repo: RepositoryDescriptor.MavenRemote, coverage: CoverageConfiguration) {
95113
project.pluginManager.apply("maven-publish")
96114

97115
if (coverage is CoverageConfiguration.Jacoco) {
@@ -109,8 +127,8 @@ private fun Project.configureIntegrationPublishingForDependency(project: Project
109127
project.extensions.configure<PublishingExtension>("publishing") {
110128
repositories {
111129
maven {
112-
name = RepositoryDescriptor.INTEGRATION_REPO_NAME
113-
url = project.uri("file://$repo")
130+
name = repo.name
131+
url = repo.url
114132
}
115133
}
116134

@@ -139,32 +157,34 @@ private fun Project.configureIntegrationPublishingForDependency(project: Project
139157
}
140158

141159
tasks.named("test") {
142-
dependsOn("${project.path}:publishIntegrationPublicationToIntegrationRepository")
160+
dependsOn("${project.path}:publishTestkitIntegrationPublicationTo${repo.capitalizedName}Repository")
143161
}
144162

145163
project.extensions.findByType(
146164
GradlePluginDevelopmentExtension::class.java
147165
)?.plugins?.forEach { plugin ->
148-
val name = "publish" + plugin.name.capitalize() + "PluginMarkerMavenPublicationToIntegrationRepository"
166+
val name = "publish" + plugin.name.simpleCapitalize() + "PluginMarkerMavenPublicationTo${repo.capitalizedName}Repository"
149167

150168
tasks.named("test") {
151169
dependsOn("${project.path}:$name")
152170
}
153171
}
154172

155173
if (coverage is CoverageConfiguration.Jacoco) {
156-
project.tasks.named<GenerateModuleMetadata>("generateMetadataFileForIntegrationPublication") {
174+
project.tasks.named<GenerateModuleMetadata>("generateMetadataFileForTestkitIntegrationPublication") {
157175
enabled = false
158176
}
159177
}
160178

161179
project.publishOnlyIf { publication, repository ->
162180
if (publication == PublicationDescriptor.INTEGRATION) {
163-
repository == RepositoryDescriptor.INTEGRATION
164-
} else if (repository == RepositoryDescriptor.INTEGRATION) {
181+
repository.isIntegration()
182+
} else if (repository.isIntegration()) {
165183
publication.isPlugin()
166184
} else {
167185
true
168186
}
169187
}
170188
}
189+
190+
fun String.simpleCapitalize() = replaceFirstChar(Char::titlecaseChar)

testkit-plugin/src/main/kotlin/com/toasttab/gradle/testkit/TestkitPlugin.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package com.toasttab.gradle.testkit
1717

1818
import com.toasttab.gradle.testkit.shared.configureIntegrationPublishing
19-
import com.toasttab.gradle.testkit.shared.integrationRepo
19+
import com.toasttab.gradle.testkit.shared.integrationDirectory
2020
import org.apache.tools.ant.filters.ReplaceTokens
2121
import org.gradle.api.Plugin
2222
import org.gradle.api.Project
@@ -48,7 +48,7 @@ class TestkitPlugin @Inject constructor(
4848
mapOf(
4949
"tokens" to mapOf(
5050
"TESTKIT_PLUGIN_VERSION" to BuildConfig.VERSION,
51-
"TESTKIT_INTEGRATION_REPO" to project.integrationRepo,
51+
"TESTKIT_INTEGRATION_REPO" to project.integrationDirectory().path,
5252
"VERSION" to "${project.version}"
5353
) + extension.replaceTokens
5454
)
@@ -69,7 +69,7 @@ class TestkitPlugin @Inject constructor(
6969

7070
systemProperty("testkit-coverage-output", "${destfile.get()}")
7171
systemProperty("testkit-projects", "${testProjectDir.get()}")
72-
systemProperty("testkit-integration-repo", project.integrationRepo)
72+
systemProperty("testkit-integration-repo", project.integrationDirectory().path)
7373
}
7474

7575
project.configureIntegrationPublishing()

0 commit comments

Comments
 (0)