Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #30 from GTMEGA/maven-publishing
Browse files Browse the repository at this point in the history
Implemented proper maven publishing as a substitute to jitpack
  • Loading branch information
basdxz authored Jan 24, 2022
2 parents c0825e3 + 3717b49 commit 3876977
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,12 @@ artifacts {
archives apiJar
}
}
// NODELETE
// This is used for invoking the publishing script. We cannot use addon.gradle,
// as it is included too early in the buildscript. We need this below artifacts{}
if(file("publishing.gradle").exists()) {
apply from: "publishing.gradle"
}

// Updating
task updateBuildScript {
Expand Down
16 changes: 16 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ modGroup = gregtech
# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
# code base or your binary. Check out this tutorial: https://blog.mattclemente.com/2017/10/13/versioning-with-git-tags/

#
# Publishing settings
#

# The server to upload the artifacts to
repositoryURL = https://gtmega.falsepattern.com/

# What name is the login information inside ~/.m2/settings.xml stored under
# (see https://gist.github.com/FalsePattern/82d93e3cfab01f671cc5f4a95931cfe3 for an example)
repositoryName = mavenpattern

# What the artifact should be called. These will be the "name" of the published package. (groupid:artifactid:version:qualifier).
# The version is determined automatically from the git version (the same way the buildscript does it)
mavenGroupId = gtmega
mavenArtifactId = gt5u

# Will update your build.gradle automatically whenever an update is available
autoUpdateBuildScript = false

Expand Down
51 changes: 51 additions & 0 deletions publishing.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apply plugin: "maven-publish"
checkPropertyExists("repositoryURL")
checkPropertyExists("repositoryName")
checkPropertyExists("mavenGroupId")
checkPropertyExists("mavenArtifactId")

def getMavenSettingsCredentials = {
String userHome = System.getProperty( "user.home" );
File mavenSettings = new File(userHome, ".m2/settings.xml")
def xmlSlurper = new XmlSlurper()
def output = xmlSlurper.parse(mavenSettings)
return output."servers"."server"
}

def getCredentials = {
def entries = getMavenSettingsCredentials()
for (entry in entries) {
if ( entry."id".text() == repositoryName ) {
return [username: entry.username.text(), password: entry.password.text()]
}
}
}

publishing {
publications {
maven(MavenPublication) {
artifact source: jar
artifact source: sourcesJar, classifier: "src"
artifact source: devJar, classifier: "dev"
if (apiPackage) {
artifact source: apiJar, classifier: "api"
}

groupId = mavenGroupId
artifactId = mavenArtifactId
version = project.version
}
}

repositories {
maven {
name = repositoryName
url = repositoryURL
def creds = getCredentials()
credentials {
username = creds == null ? "none" : creds.username
password = creds == null ? "none" : creds.password
}
}
}
}

0 comments on commit 3876977

Please sign in to comment.