From 4ac9eb314d41b696ec79c31cd8f91e2b0f1447f3 Mon Sep 17 00:00:00 2001 From: layue13 Date: Tue, 27 Oct 2026 19:40:07 +0000 Subject: [PATCH 1/2] build: derive Maven endpoints from an overridable base --- build.gradle | 63 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 57 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 9a49f8a..fa705a6 100644 --- a/build.gradle +++ b/build.gradle @@ -7,6 +7,45 @@ def gitCommit = providers.exec { group = 'uk.potatolab' version = "${providers.gradleProperty('modVersion').get()}-${gitCommit}" +// --------------------------------------------------------------------------- +// TDLM Maven endpoints. +// +// The organisation default lives in gradle.properties as mavenPublishUrl, a normal Gradle +// property. A runner overrides it through Gradle itself - no bespoke variable: +// +// export ORG_GRADLE_PROJECT_mavenPublishUrl=https:///repository/maven-releases +// # or: ./gradlew -PmavenPublishUrl=https:///repository/maven-releases ... +// +// Only the HOST+repository-root part of that value is used as the base; the repository name +// is recomputed per artifact below. So pointing it at the accelerator moves both endpoints. +// +// resolution -> $base/repository/maven-public (the only address consumers need) +// publication -> $base/repository/maven-releases or maven-snapshots, chosen by version +// +// The two hosted repos enforce mutually exclusive policies: a SNAPSHOT sent to +// maven-releases is rejected with 400, and a release sent to maven-snapshots likewise. +// That is why one fixed publish URL cannot work, and why this splits them. +def tdlmPublishBase = { + // Accept any of: , /repository/maven-, /repository/maven-public + def configured = (project.findProperty('mavenPublishUrl') ?: 'https://maven.nest.potatolab.uk:8443').toString() + def normalised = configured.replaceAll('/+$', '') + int idx = normalised.indexOf('/repository/') + if (idx >= 0) normalised = normalised.substring(0, idx) + normalised +}() +def tdlmResolveUrl = "$tdlmPublishBase/repository/maven-public" +def tdlmPublishUrl = { String version -> + [tdlmPublishBase, 'repository', (version ==~ /(?i).*[-.]SNAPSHOT([-._].*)?/ ? 'maven-snapshots' : 'maven-releases')].join('/') +} +def tdlmCredentials = { repo -> + if (System.getenv('MAVEN_USER') && System.getenv('MAVEN_PASSWORD')) { + repo.credentials { + username = System.getenv('MAVEN_USER') + password = System.getenv('MAVEN_PASSWORD') + } + } +} + afterEvaluate { publishing.publications.named('maven', MavenPublication) { groupId = project.group @@ -18,13 +57,25 @@ afterEvaluate { repositories { maven { name = 'TDLM Maven' - url = 'https://git.nest.potatolab.uk:8443/api/packages/TDLM/maven' + url = tdlmResolveUrl content { includeGroup "uk.potatolab" } - if (System.getenv('MAVEN_USER') && System.getenv('MAVEN_PASSWORD')) { - credentials { - username = System.getenv('MAVEN_USER') - password = System.getenv('MAVEN_PASSWORD') - } + } +} + +// The GTNH plugin creates its publishing repository only when MAVEN_USER/MAVEN_PASSWORD are +// present, and it aims that repository at the single mavenPublishUrl. Re-point it so the +// target follows the artifact version, and keep credentials attached. +afterEvaluate { + def tdlmTargets = publishing.repositories.withType(org.gradle.api.artifacts.repositories.MavenArtifactRepository) + tdlmTargets.configureEach { repo -> + repo.url = uri(tdlmPublishUrl(project.version.toString())) + tdlmCredentials(repo) + } + if (tdlmTargets.isEmpty()) { + publishing.repositories.maven { repo -> + repo.name = 'tdlm' + repo.url = uri(tdlmPublishUrl(project.version.toString())) + tdlmCredentials(repo) } } } -- 2.47.3 From 26e3104cd3aa56c3b337e6e1088ee9694fe4129e Mon Sep 17 00:00:00 2001 From: layue13 Date: Tue, 27 Oct 2026 19:40:07 +0000 Subject: [PATCH 2/2] build: derive Maven endpoints from an overridable base --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 8e7788c..1b7d138 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,4 +12,4 @@ disableSpotless = true disableCheckstyle = true org.gradle.jvmargs = -Xmx2G usesMavenPublishing = true -mavenPublishUrl = https://git.nest.potatolab.uk:8443/api/packages/TDLM/maven +mavenPublishUrl = https\://maven.nest.potatolab.uk:8443/repository/maven-releases -- 2.47.3