mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-15 00:14:28 -04:00
Skip publishing previously published artifacts. (#4501)
* Skip publishing previously published artifacts. * Use new HTTP client. * Opps * Spotless * Close the http client
This commit is contained in:
parent
aa6d566c45
commit
97ecb05309
1 changed files with 36 additions and 0 deletions
36
build.gradle
36
build.gradle
|
@ -29,6 +29,9 @@ import groovy.json.JsonSlurper
|
|||
import org.apache.commons.codec.digest.DigestUtils
|
||||
import net.fabricmc.fabric.impl.build.CommitHashValueSource
|
||||
import net.fabricmc.fabric.impl.build.GitBranchValueSource
|
||||
import java.net.http.HttpClient
|
||||
import java.net.http.HttpRequest
|
||||
import java.net.http.HttpResponse
|
||||
|
||||
def getSubprojectVersion(Project project) {
|
||||
// Get the version from the gradle.properties file
|
||||
|
@ -553,6 +556,39 @@ subprojects {
|
|||
}
|
||||
}
|
||||
|
||||
def projectName = it.name
|
||||
def projectVersion = getSubprojectVersion(it)
|
||||
|
||||
// Skip publishing if the artifact already exists on the maven server
|
||||
tasks.withType(PublishToMavenRepository).configureEach {
|
||||
onlyIf {
|
||||
if (!providers.environmentVariable("MAVEN_URL").present) {
|
||||
// Always try to publish if the maven url is not set (e.g locally)
|
||||
return true
|
||||
}
|
||||
|
||||
def artifactPath = "https://maven.fabricmc.net/net/fabricmc/fabric-api/${projectName}/${projectVersion}/${projectName}-${projectVersion}.pom"
|
||||
|
||||
boolean exists = HttpClient.newHttpClient().withCloseable { client ->
|
||||
def request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(artifactPath))
|
||||
.method("HEAD", HttpRequest.BodyPublishers.noBody())
|
||||
.build()
|
||||
|
||||
def response = client.send(request, HttpResponse.BodyHandlers.discarding())
|
||||
response.statusCode() == 200
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
logger.lifecycle("${projectName}-${projectVersion}.pom has already been published")
|
||||
} else {
|
||||
logger.lifecycle("${projectName}-${projectVersion}.pom does not exist, publishing")
|
||||
}
|
||||
|
||||
return !exists
|
||||
}
|
||||
}
|
||||
|
||||
// We manually handle the pom generation
|
||||
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue