build: derive Maven endpoints from an overridable base #6
No files matched your search
+57
-6
@@ -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://<accelerator>/repository/maven-releases
|
||||
// # or: ./gradlew -PmavenPublishUrl=https://<accelerator>/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: <base>, <base>/repository/maven-<repo>, <base>/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)
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
Reference in new issue
Block a user