Skip to content

Commit 632a54a

Browse files
author
Sergey Mashkov
committed
Fix publication verifier
1 parent 3b63b02 commit 632a54a

File tree

2 files changed

+49
-9
lines changed

2 files changed

+49
-9
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ buildscript {
2424
def skipPublish = ['benchmarks', 'binary-compatibility-validator']
2525

2626
apply from: "gradle/experimental.gradle"
27+
apply from: rootProject.file('gradle/verifier.gradle')
2728

2829
allprojects {
2930
project.ext.hostManager = new HostManager()
@@ -53,7 +54,7 @@ allprojects {
5354
apply from: rootProject.file("gradle/native.gradle")
5455

5556
apply from: rootProject.file("gradle/publish.gradle")
56-
apply from: rootProject.file('gradle/verifier.gradle')
57+
5758
}
5859

5960
kotlin {

gradle/verifier.gradle

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def isEmptyTagList(node) {
1818
return node == null || node.size() == 0
1919
}
2020

21-
def verifyArtifact(File versionDir, List<File> files, String ext) {
21+
def verifyArtifact(File versionDir, List<File> files, String ext, String kind) {
2222
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 $kind)")
2424
}
2525
}
2626

@@ -98,9 +98,43 @@ String packaging(File moduleDir) {
9898
return packaing
9999
}
100100

101-
def kinds = kotlin.targets.collect { it.name }
101+
def lookupTasks = {
102+
def targetNames = kotlin.targets.collect { it.name }
103+
def tasks = []
102104

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) {
104138
doLast {
105139
def m2 = new File(rootProject.buildDir, 'm2')
106140
def pomFiles = []
@@ -133,11 +167,16 @@ task verifyPublications(dependsOn: { [cleanPublications] + kinds.collect { "publ
133167
if (versionDir.exists()) {
134168
def files = versionDir.listFiles()?.findAll { it.isFile() } ?: []
135169

170+
def moduleKind = guessModuleKind(versionDir, files.find { it.name.endsWith(".pom") })
171+
136172
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+
}
141180

142181
verified ++
143182
}

0 commit comments

Comments
 (0)