@@ -18,9 +18,9 @@ def isEmptyTagList(node) {
18
18
return node == null || node. size() == 0
19
19
}
20
20
21
- def verifyArtifact (File versionDir , List<File > files , String ext ) {
21
+ def verifyArtifact (File versionDir , List<File > files , String ext , String kind ) {
22
22
if (files. count { it. name. toLowerCase(). endsWith(ext) } == 0 ) {
23
- throw new GradleException (" No $ext artifact found at $versionDir " )
23
+ throw new GradleException (" No $ext artifact found at $versionDir (kind $k ind ) " )
24
24
}
25
25
}
26
26
@@ -98,9 +98,43 @@ String packaging(File moduleDir) {
98
98
return packaing
99
99
}
100
100
101
- def kinds = kotlin. targets. collect { it. name }
101
+ def lookupTasks = {
102
+ def targetNames = kotlin. targets. collect { it. name }
103
+ def tasks = []
102
104
103
- task verifyPublications (dependsOn : { [cleanPublications] + kinds. collect { " publish${ it.capitalize()} PublicationToTestLocalRepository" } }) {
105
+ allprojects {
106
+ tasks + = targetNames. collect { project. tasks. findByName(" publish${ it.capitalize()} PublicationToTestLocalRepository" ) }
107
+ .findAll()
108
+ }
109
+
110
+ return [cleanPublications] + tasks
111
+ }
112
+
113
+ // returns jvm, js, native or some native target name
114
+ String guessModuleKind (File dir , File pomFile ) {
115
+ def artifactId_ = new XmlSlurper (false , true ). parse(pomFile). artifactId. text()
116
+ def kind = null
117
+
118
+ allprojects {
119
+ project. publishing. publications. findAll { ! it. name. contains(' -test' ) && it. artifactId == artifactId_ }. each {
120
+ kind = it. name
121
+ }
122
+ }
123
+
124
+ if (! kind) {
125
+ allprojects { project ->
126
+ println " project $project . name "
127
+ project. publishing. publications. each {
128
+ println " publication $it . name with ${ it.artifactId} (looking for $artifactId_ , found = ${ it.artifactId == artifactId_} )"
129
+ }
130
+ }
131
+ throw new GradleException (" Not found" )
132
+ }
133
+
134
+ return kind
135
+ }
136
+
137
+ task verifyPublications (dependsOn : lookupTasks) {
104
138
doLast {
105
139
def m2 = new File (rootProject. buildDir, ' m2' )
106
140
def pomFiles = []
@@ -133,11 +167,16 @@ task verifyPublications(dependsOn: { [cleanPublications] + kinds.collect { "publ
133
167
if (versionDir. exists()) {
134
168
def files = versionDir. listFiles()?. findAll { it. isFile() } ?: []
135
169
170
+ def moduleKind = guessModuleKind(versionDir, files. find { it. name. endsWith(" .pom" ) })
171
+
136
172
def packaging = ' .' + packaging(versionDir)
137
- verifyArtifact(versionDir, files, packaging)
138
- verifyArtifact(versionDir, files, ' -javadoc.jar' )
139
- verifyArtifact(versionDir, files, ' -sources.jar' )
140
- verifyArtifact(versionDir, files, ' .module' )
173
+ verifyArtifact(versionDir, files, packaging, moduleKind)
174
+ verifyArtifact(versionDir, files, ' -javadoc.jar' , moduleKind)
175
+ verifyArtifact(versionDir, files, ' -sources.jar' , moduleKind)
176
+
177
+ if (moduleKind != ' js' && moduleKind != ' jvm' && moduleKind != ' metadata' ) {
178
+ verifyArtifact(versionDir, files, ' .module' , moduleKind)
179
+ }
141
180
142
181
verified ++
143
182
}
0 commit comments