1+ buildscript {
2+ repositories {
3+ maven {
4+ url " https://plugins.gradle.org/m2/"
5+ }
6+ }
7+ dependencies {
8+ classpath ' org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r'
9+ }
10+ }
11+
112apply plugin : ' java'
213apply plugin : ' idea'
314apply plugin : ' eclipse'
415apply plugin : ' maven'
516
17+ project. ext {
18+ GIT_INFO = gitInfo(rootProject. file(' .' ))
19+ }
20+
621group = ' net.minecraftforge.gradle'
7- version = ' 1.0-SNAPSHOT'
22+ version = " ${ project.ext.GIT_INFO.tag} .${ project.ext.GIT_INFO.offset} "
23+ println " Version $version "
824archivesBaseName = ' ForgeGradle'
925targetCompatibility = ' 1.6'
1026sourceCompatibility = ' 1.6'
1127
1228repositories {
1329 maven {
1430 name = " forge"
15- url = " http ://files .minecraftforge.net/maven "
31+ url = " https ://maven .minecraftforge.net/"
1632 }
1733 mavenCentral()
1834}
@@ -58,14 +74,15 @@ artifacts { archives jar }
5874
5975uploadArchives {
6076 repositories {
61- if (project. hasProperty(" filesmaven" )) {
62- logger. info(' Publishing to files server' )
63-
6477 mavenDeployer {
6578 configuration = configurations. deployerJars
6679
67- repository(url : project. filesmaven. url) {
68- authentication(userName : project. filesmaven. username, privateKey : project. filesmaven. key)
80+ if (System . env. MAVEN_USER ) {
81+ repository(url : " https://maven.minecraftforge.net/" ) {
82+ authentication(userName : System . env. MAVEN_USER , password : System . env. MAVEN_PASSWORD )
83+ }
84+ } else {
85+ repository(url : ' file://localhost/' + project. file(' repo' ). getAbsolutePath())
6986 }
7087
7188 pom {
@@ -114,10 +131,46 @@ uploadArchives {
114131 }
115132 }
116133 }
117- }
118- else
119- {
120- add project. repositories. mavenLocal()
121- }
122134 }
123135}
136+
137+ def gitInfo (dir ) {
138+ String . metaClass. rsplit = { String del , int limit = -1 ->
139+ def lst = new ArrayList ()
140+ def x = 0 , idx
141+ def tmp = delegate
142+ while ((idx = tmp. lastIndexOf(del)) != -1 && (limit == -1 || x++ < limit)) {
143+ lst. add(0 , tmp. substring(idx + del. length(), tmp. length()))
144+ tmp = tmp. substring(0 , idx)
145+ }
146+ lst. add(0 , tmp)
147+ return lst
148+ }
149+
150+ def git = null
151+ try {
152+ git = org.eclipse.jgit.api.Git . open(dir)
153+ } catch (org.eclipse.jgit.errors.RepositoryNotFoundException e) {
154+ return [
155+ tag : ' 0.0' ,
156+ offset : ' 0' ,
157+ hash : ' 00000000' ,
158+ branch : ' master' ,
159+ commit : ' 0000000000000000000000' ,
160+ abbreviatedId : ' 00000000'
161+ ]
162+ }
163+ def desc = git. describe(). setLong(true ). setTags(true ). call(). rsplit(' -' , 2 )
164+ def head = git. repository. exactRef(' HEAD' )
165+ def longBranch = head. symbolic ? head?. target?. name : null // matches Repository.getFullBranch() but returning null when on a detached HEAD
166+
167+ def ret = [:]
168+ ret. tag = desc[0 ]
169+ ret. offset = desc[1 ]
170+ ret. hash = desc[2 ]
171+ ret. branch = longBranch != null ? org.eclipse.jgit.lib.Repository . shortenRefName(longBranch) : null
172+ ret. commit = org.eclipse.jgit.lib.ObjectId . toString(head. objectId)
173+ ret. abbreviatedId = head. objectId. abbreviate(8 ). name()
174+
175+ return ret
176+ }
0 commit comments