aboutsummaryrefslogtreecommitdiff
path: root/buildscript/forge-1.7.gradle
blob: f094cbbd1b1873a1286d09e7eff226ce363a958e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/** Common code for Forge 1.7.10 builds */

apply plugin: 'forge'

ext.publishDir = project.multiproject_structure.toBoolean() ? "${projectDir}/../publish" : "${projectDir}/publish"

def getCommitVersion(){
	try {
		def commitHashProc = "python3 ${ext.publishDir}/get_version.py".execute()
		commitHashProc.waitFor()
		if(commitHashProc.exitValue() == 0){
			def commitHash = commitHashProc.text.trim()
			
			return commitHash
		} else {
			println commitHashProc.err.text
			throw new Exception("get_version.py exited with non-zero return value")
		}
	} catch(Exception e){
		println "Failed to run get_version.py: " + e.getMessage()
	}
	return "UNKNOWN" // fallback
}

project.version = getCommitVersion()

group = project.group
archivesBaseName = "${project.archives_base}-${project.minecraft_version}"

minecraft {
    version = "${project.minecraft_version}-${project.forge_version}"
    runDir = "run"
	replace '@VERSION@', project.version
}

// These settings allow you to choose what version of Java you want to be compatible with. Forge 1.7.10 runs on Java 6 to 8.
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
	maven {
		name = "chickenbones"
		url = "http://chickenbones.net/maven/"
	}
}

configurations {
    embed
    compile.extendsFrom(embed)
	shade
    compile.extendsFrom(shade)
}

if(project.enable_mixin.toBoolean()) {
	apply from: "buildscript/forge-1.7-mixin.gradle"
}

apply from: "project.gradle"

jar {
    from(sourceSets.main.output);

    // embed libraries in jar
    from configurations.embed.collect {
        exclude '**/LICENSE', '**/LICENSE.txt'
        it.isDirectory() ? it : zipTree(it)
    }
	
	configurations.shade.each { dep ->
        from(project.zipTree(dep)){
            exclude '**/LICENSE', '**/LICENSE.txt', 'META-INF', 'META-INF/**'
        }
    }
}

processResources {
    // This will ensure that this task is redone when the versions or any
	// user-defined properties change.
    inputs.property "version", version
    inputs.property "mcversion", project.minecraft.version
	inputs.properties project.ext.getProperties()

    filesMatching('*.info') {
        expand project.properties
    }
}

// Ensures that the encoding of source files is set to UTF-8, see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

// This task creates a .jar file containing the source code of this mod.
task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = "sources"
    from sourceSets.main.allSource
}

// This task creates a .jar file containing a deobfuscated version of this mod, for other developers to use in a development environment.
task devJar(type: Jar) {
    classifier = "dev"
    from sourceSets.main.output
}

// Creates the listed artifacts on building the mod.
artifacts {
    archives sourcesJar
    archives devJar
}

// Add git commit hash to MANIFEST.MF

def getCommitHash(){
	try {
		def commitHashProc = "git describe --always --dirty".execute()
		commitHashProc.waitFor()
		if(commitHashProc.exitValue() == 0){
			def commitHash = commitHashProc.text.trim()
			
			return commitHash
		} else {
			println commitHashProc.err.text
			throw new Exception("git describe exited with non-zero return value")
		}
	} catch(Exception e){
		println "Failed to get commit version: " + e.getMessage()
	}
	return "UNKNOWN" // fallback
}


jar {
    manifest {
        attributes (
            'Commit-ID': getCommitHash(),
        )
    }
}