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.1-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 maven {
1834 name = " sonatype"
@@ -62,16 +78,17 @@ artifacts { archives jar }
6278
6379uploadArchives {
6480 repositories {
65- if (project. hasProperty(" filesmaven" )) {
66- logger. info(' Publishing to files server' )
67-
6881 mavenDeployer {
6982 configuration = configurations. deployerJars
7083
71- repository(url : project. filesmaven. url) {
72- authentication(userName : project. filesmaven. username, privateKey : project. filesmaven. key)
84+ if (System . env. MAVEN_USER ) {
85+ repository(url : " https://maven.minecraftforge.net/" ) {
86+ authentication(userName : System . env. MAVEN_USER , password : System . env. MAVEN_PASSWORD )
87+ }
88+ } else {
89+ repository(url : ' file://localhost/' + project. file(' repo' ). getAbsolutePath())
7390 }
74-
91+
7592 pom {
7693 groupId = project. group
7794 version = project. version
@@ -118,10 +135,46 @@ uploadArchives {
118135 }
119136 }
120137 }
121- }
122- else
123- {
124- add project. repositories. mavenLocal()
125- }
126138 }
127139}
140+
141+ def gitInfo (dir ) {
142+ String . metaClass. rsplit = { String del , int limit = -1 ->
143+ def lst = new ArrayList ()
144+ def x = 0 , idx
145+ def tmp = delegate
146+ while ((idx = tmp. lastIndexOf(del)) != -1 && (limit == -1 || x++ < limit)) {
147+ lst. add(0 , tmp. substring(idx + del. length(), tmp. length()))
148+ tmp = tmp. substring(0 , idx)
149+ }
150+ lst. add(0 , tmp)
151+ return lst
152+ }
153+
154+ def git = null
155+ try {
156+ git = org.eclipse.jgit.api.Git . open(dir)
157+ } catch (org.eclipse.jgit.errors.RepositoryNotFoundException e) {
158+ return [
159+ tag : ' 0.0' ,
160+ offset : ' 0' ,
161+ hash : ' 00000000' ,
162+ branch : ' master' ,
163+ commit : ' 0000000000000000000000' ,
164+ abbreviatedId : ' 00000000'
165+ ]
166+ }
167+ def desc = git. describe(). setLong(true ). setTags(true ). call(). rsplit(' -' , 2 )
168+ def head = git. repository. exactRef(' HEAD' )
169+ def longBranch = head. symbolic ? head?. target?. name : null // matches Repository.getFullBranch() but returning null when on a detached HEAD
170+
171+ def ret = [:]
172+ ret. tag = desc[0 ]
173+ ret. offset = desc[1 ]
174+ ret. hash = desc[2 ]
175+ ret. branch = longBranch != null ? org.eclipse.jgit.lib.Repository . shortenRefName(longBranch) : null
176+ ret. commit = org.eclipse.jgit.lib.ObjectId . toString(head. objectId)
177+ ret. abbreviatedId = head. objectId. abbreviate(8 ). name()
178+
179+ return ret
180+ }
0 commit comments