@@ -30,22 +30,31 @@ import org.gradle.kotlin.dsl.named
30
30
import org.gradle.kotlin.dsl.register
31
31
import org.gradle.kotlin.dsl.withType
32
32
import org.gradle.plugin.devel.GradlePluginDevelopmentExtension
33
+ import java.net.URI
33
34
34
35
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
+ }
37
47
38
48
companion object {
39
- const val INTEGRATION_REPO_NAME = " integration"
40
- val INTEGRATION = MavenRemote (INTEGRATION_REPO_NAME )
49
+ const val INTEGRATION_REPO_NAME_PREFIX = " testkitIntegrationFor"
41
50
}
42
51
}
43
52
44
53
data class PublicationDescriptor (val name : String ) {
45
54
fun isPlugin () = name.endsWith(" PluginMarkerMaven" )
46
55
47
56
companion object {
48
- const val INTEGRATION_PUBLICATION_NAME = " integration "
57
+ const val INTEGRATION_PUBLICATION_NAME = " testkitIntegration "
49
58
val INTEGRATION = PublicationDescriptor (INTEGRATION_PUBLICATION_NAME )
50
59
}
51
60
}
@@ -59,17 +68,26 @@ fun Project.publishOnlyIf(predicate: (PublicationDescriptor, RepositoryDescripto
59
68
60
69
project.tasks.withType<PublishToMavenRepository > {
61
70
onlyIf {
62
- predicate(PublicationDescriptor (publication.name), RepositoryDescriptor .MavenRemote (repository.name))
71
+ predicate(PublicationDescriptor (publication.name), RepositoryDescriptor .MavenRemote (repository.name, repository.url ))
63
72
}
64
73
}
65
74
}
66
75
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
68
77
69
78
fun Project.configureIntegrationPublishing (
70
79
configuration : String = "runtimeClasspath"
71
80
) {
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
+ )
73
91
74
92
afterEvaluate {
75
93
val coverage = project.coverage()
@@ -87,11 +105,11 @@ fun Project.configureIntegrationPublishing(
87
105
}
88
106
89
107
tasks.named(" test" ) {
90
- dependsOn(" publishIntegrationPublicationToIntegrationRepository " )
108
+ dependsOn(" publishTestkitIntegrationPublicationTo ${repo.capitalizedName} Repository " )
91
109
}
92
110
}
93
111
94
- private fun Project.configureIntegrationPublishingForDependency (project : Project , repo : Any , coverage : CoverageConfiguration ) {
112
+ private fun Project.configureIntegrationPublishingForDependency (project : Project , repo : RepositoryDescriptor . MavenRemote , coverage : CoverageConfiguration ) {
95
113
project.pluginManager.apply (" maven-publish" )
96
114
97
115
if (coverage is CoverageConfiguration .Jacoco ) {
@@ -109,8 +127,8 @@ private fun Project.configureIntegrationPublishingForDependency(project: Project
109
127
project.extensions.configure<PublishingExtension >(" publishing" ) {
110
128
repositories {
111
129
maven {
112
- name = RepositoryDescriptor . INTEGRATION_REPO_NAME
113
- url = project.uri( " file:// $ repo" )
130
+ name = repo.name
131
+ url = repo.url
114
132
}
115
133
}
116
134
@@ -139,32 +157,34 @@ private fun Project.configureIntegrationPublishingForDependency(project: Project
139
157
}
140
158
141
159
tasks.named(" test" ) {
142
- dependsOn(" ${project.path} :publishIntegrationPublicationToIntegrationRepository " )
160
+ dependsOn(" ${project.path} :publishTestkitIntegrationPublicationTo ${repo.capitalizedName} Repository " )
143
161
}
144
162
145
163
project.extensions.findByType(
146
164
GradlePluginDevelopmentExtension ::class .java
147
165
)?.plugins?.forEach { plugin ->
148
- val name = " publish" + plugin.name.capitalize () + " PluginMarkerMavenPublicationToIntegrationRepository "
166
+ val name = " publish" + plugin.name.simpleCapitalize () + " PluginMarkerMavenPublicationTo ${repo.capitalizedName} Repository "
149
167
150
168
tasks.named(" test" ) {
151
169
dependsOn(" ${project.path} :$name " )
152
170
}
153
171
}
154
172
155
173
if (coverage is CoverageConfiguration .Jacoco ) {
156
- project.tasks.named<GenerateModuleMetadata >(" generateMetadataFileForIntegrationPublication " ) {
174
+ project.tasks.named<GenerateModuleMetadata >(" generateMetadataFileForTestkitIntegrationPublication " ) {
157
175
enabled = false
158
176
}
159
177
}
160
178
161
179
project.publishOnlyIf { publication, repository ->
162
180
if (publication == PublicationDescriptor .INTEGRATION ) {
163
- repository == RepositoryDescriptor . INTEGRATION
164
- } else if (repository == RepositoryDescriptor . INTEGRATION ) {
181
+ repository.isIntegration()
182
+ } else if (repository.isIntegration() ) {
165
183
publication.isPlugin()
166
184
} else {
167
185
true
168
186
}
169
187
}
170
188
}
189
+
190
+ fun String.simpleCapitalize () = replaceFirstChar(Char ::titlecaseChar)
0 commit comments