Skip to content

Commit b6ead59

Browse files
committed
allow custom maven publishing
1 parent d62188c commit b6ead59

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

build.gradle

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ plugins {
1818
id 'java'
1919
id 'java-library'
2020
id 'eclipse'
21+
id 'maven-publish'
2122
id 'org.jetbrains.gradle.plugin.idea-ext' version '1.1.7'
2223
id 'com.gtnewhorizons.retrofuturagradle' version '1.3.+'
23-
id 'scala' apply false
2424
id 'net.darkhax.curseforgegradle' version '1.0.+' apply false
2525
id 'com.modrinth.minotaur' version '2.7.+' apply false
2626
id 'com.diffplug.spotless' version '6.13.0' apply false
@@ -66,6 +66,7 @@ propertyDefaultIfUnset("modrinthRelations", "")
6666
propertyDefaultIfUnset("curseForgeProjectId", "")
6767
propertyDefaultIfUnset("curseForgeRelations", "")
6868
propertyDefaultIfUnset("releaseType", "release")
69+
propertyDefaultIfUnset("customMavenPublishUrl", "")
6970
propertyDefaultIfUnset("enableModernJavaSyntax", false)
7071
propertyDefaultIfUnset("enableSpotless", false)
7172
propertyDefaultIfUnset("enableJUnit", false)
@@ -739,6 +740,39 @@ def addModrinthDep(String scope, String type, String name) {
739740
project.modrinth.dependencies.add(dep)
740741
}
741742

743+
if (customMavenPublishUrl) {
744+
String publishedVersion = modVersion
745+
746+
publishing {
747+
publications {
748+
create('maven', MavenPublication) {
749+
//noinspection GroovyAssignabilityCheck
750+
from components.java
751+
752+
if (apiPackage) {
753+
artifact apiJar
754+
}
755+
756+
// providers is not available here, use System for getting env vars
757+
groupId = System.getenv('ARTIFACT_GROUP_ID') ?: project.group
758+
artifactId = System.getenv('ARTIFACT_ID') ?: project.name
759+
version = System.getenv('RELEASE_VERSION') ?: publishedVersion
760+
}
761+
}
762+
763+
repositories {
764+
maven {
765+
url = customMavenPublishUrl
766+
allowInsecureProtocol = !customMavenPublishUrl.startsWith('https')
767+
credentials {
768+
username = providers.environmentVariable('MAVEN_USER').getOrElse('NONE')
769+
password = providers.environmentVariable('MAVEN_PASSWORD').getOrElse('NONE')
770+
}
771+
}
772+
}
773+
}
774+
}
775+
742776

743777
// Buildscript updating
744778

gradle.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ releaseType = release
103103
# Prevent the source code from being published
104104
noPublishedSources = false
105105

106+
107+
# Publish to a custom maven location. Follows a few rules:
108+
# Group ID can be set with the 'ARTIFACT_GROUP_ID' environment variable, default to 'project.group'
109+
# Artifact ID can be set with the 'ARTIFACT_ID' environment variable, default to 'project.name'
110+
# Version can be set with the 'RELEASE_VERSION' environment variable, default to 'modVersion'
111+
# For maven credentials:
112+
# Username is set with the 'MAVEN_USER' environment variable, default to "NONE"
113+
# Password is set with the 'MAVEN_PASSWORD' environment variable, default to "NONE"
114+
customMavenPublishUrl =
115+
106116
# Enable spotless checks
107117
# Enforces code formatting on your source code
108118
# By default this will use the files found here: https://github.com/GregTechCEu/Buildscripts/tree/master/spotless

0 commit comments

Comments
 (0)