@@ -103,8 +103,42 @@ tasks.withType(PublishToMavenLocal).configureEach {
103
103
}
104
104
}
105
105
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
+
106
139
tasks. withType(PublishToMavenRepository ). configureEach {
107
140
doFirst {
141
+ downloadMavenMetadataFile(publication. groupId, publication. artifactId)
108
142
logger. lifecycle(" PublishToMavenRepository ({} : {})" , publication. name, repository. name)
109
143
logger. lifecycle(" - {} : {} : {} " , publication. groupId, publication. artifactId, publication. pom. packaging)
110
144
logger. lifecycle(" - artifacts ({})..." , publication. artifacts. size())
0 commit comments