Skip to content

Commit b053e41

Browse files
committed
JReleaser fix problem with maven-metadata.xml not containing previous release versions info
1 parent 25f78c3 commit b053e41

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

local-build-plugins/src/main/groovy/local.publishing.gradle

+34
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,42 @@ tasks.withType(PublishToMavenLocal).configureEach {
103103
}
104104
}
105105

106+
def buildMavenMetadataXmlURI(groupId,artifactId) {
107+
def snapshotRepo = "https://oss.sonatype.org/content/repositories/snapshots/"
108+
def mavenRepo = "https://repo.maven.apache.org/maven2/"
109+
def metadataXml = "${groupId.replace(".", "/")}/${artifactId}/maven-metadata.xml"
110+
111+
if (ormBuildDetails.hibernateVersion.isSnapshot) {
112+
return "${snapshotRepo}${metadataXml}"
113+
} else {
114+
return "${mavenRepo}${metadataXml}"
115+
}
116+
}
117+
118+
/*
119+
Needed because when publishing to the local staging folder the
120+
maven-metadata.xml generated does not contain all the previous published versions
121+
*/
122+
def downloadMavenMetadataFile(groupId, artifactId) {
123+
124+
def destinationFolderName = "staging-deploy${File.separator}maven${File.separator}${groupId.replace(".", File.separator)}${File.separator}${artifactId}"
125+
def destinationFolder = rootProject.layout.buildDirectory.dir(destinationFolderName).get()
126+
127+
def asFile = destinationFolder.getAsFile()
128+
if (!asFile.exists()) {
129+
asFile.mkdirs()
130+
}
131+
def destinationFile = new File(asFile.toString() + "/maven-metadata.xml")
132+
133+
def metadataFileURI = buildMavenMetadataXmlURI(groupId, artifactId)
134+
new URI(metadataFileURI).toURL().withInputStream {
135+
i -> destinationFile.withOutputStream { it << i }
136+
}
137+
}
138+
106139
tasks.withType(PublishToMavenRepository).configureEach {
107140
doFirst {
141+
downloadMavenMetadataFile(publication.groupId, publication.artifactId)
108142
logger.lifecycle("PublishToMavenRepository ({} : {})", publication.name, repository.name)
109143
logger.lifecycle(" - {} : {} : {} ", publication.groupId, publication.artifactId, publication.pom.packaging)
110144
logger.lifecycle(" - artifacts ({})...", publication.artifacts.size())

0 commit comments

Comments
 (0)