-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathboilerplate.gradle
194 lines (159 loc) · 5.46 KB
/
boilerplate.gradle
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//--- Gradle Dependencies
apply plugin: "net.minecraftforge.gradle.forge"
apply plugin: 'idea'
apply plugin: 'gradleutils'
//--- Script Utilties
project.getOr = {String envProp, projectProp -> System.getenv(envProp) ?: projectProp}
project.logFile = {LogLevel logLevel, String file -> logger.log(logLevel, new File('gradle/docs/'+file+'.txt').getText('UTF-8'))}
project.printDocs = {String file -> println(new File('gradle/docs/'+file+'.txt').getText('UTF-8'))}
//--- Project SourceSets
sourceSets {
main
test
}
idea {
project {
jdkName = '1.8'
languageLevel = '1.8'
}
module {
name file("./").name
outputDir = compileJava.destinationDir
testOutputDir = compileTestJava.destinationDir
}
}
tasks.register('additionalIntellijSettings', Copy) {
from 'gradle/docs/idea/'
include "*"
into '.idea'
}
tasks.idea.dependsOn additionalIntellijSettings
//--- Project Defaults
setVersion(modVersion)
setGroup(modGroup)
setArchivesBaseName(modName)
//Ensures no compilation errors due to unrecognised unicode characters
compileJava.options.encoding = 'UTF-8'
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
//--- Settings
minecraft {
version = modForge
runDir = "run"
replace "@VERSION@":modVersion
mappings = modMappings
useDepAts = true
}
//--- Handling custom.gradle
//To use personalized options when working with the mod create a file named custom.gradle
//The file is not sychronised with GitHub and can be used i.e. to store username and password
//Thanks to BluSunrize for the idea (taken from IE)
// We have to put it **BEFORE** any other gradle files are parsed.
def customGradle = rootProject.file('custom.gradle')
if (customGradle.exists()) {
apply from: customGradle
}
//--- Include the ModWorks Processor
if(ii_useModworksPreprocessor.asBoolean())
apply from: rootProject.file("gradle/modworks.gradle")
//--- Include Minecraft JUnit
if(ii_useJUnit.asBoolean())
apply from: rootProject.file("gradle/junit.gradle")
compileJava {
logFile(LogLevel.WARN, "gradlephant")
logger.log(LogLevel.WARN, ii_gradlephantTitle)
logger.log(LogLevel.WARN, ii_gradlephantLink+'\n')
if(ii_printSourceSets.toBoolean())
{
logger.log(LogLevel.WARN, 'SourceSets in Project: ')
sourceSets.each { srcSet ->
println "> ["+srcSet.name+"]"
print " - Sources: "+srcSet.allJava.srcDirs+"\n"
}
println ""
}
println 'This mod uses Team II\'s Mod Setup Script, run [gradlew modSetupHelp].'
if(ii_generateCoreJar=='true')
{
println 'This mod will generate a [core jar] and place it inside its [main jar] during build.'
println 'For this, a valid fingerprint and configured keystore is needed.'
}
else
println 'This mod will not generate a [core jar] inside its [main jar]. Enable it in [gradle.properties] if needed.'
if(ii_useModworksPreprocessor)
println 'This mod has ModWorks annotation processor enabled, check out https://github.com/Team-Immersive-Intelligence/ModworksProcessor for more information.'
if(ii_useJUnit)
println 'This mod has JUnit tests enabled, check out https://github.com/Team-Immersive-Intelligence/Libelle for more information.'
}
//--- Generating Deobfed Jar
tasks.register('deobfJar', Jar) {
from sourceSets.main.output
classifier = 'deobf'
manifest {
attributes 'FMLAT': modATPath
attributes 'Maven-Artifact': modGroup + ':' + modName + ':' + modVersion
}
}
artifacts {
archives deobfJar
}
//--- Resource Processing
processResources {
//this will ensure that this task is redone when the versions change.
inputs.property "version", modVersion
inputs.property "mcversion", project.minecraft.version
//copy everything else except the mcmod.info and excluded files
//setDuplicatesStrategy('exclude')
//replace stuff in mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace properties
expand 'version': modVersion, 'mcversion': project.minecraft.version
}
//Exclude GIMP images
exclude '**/*.xcf'
//Exclude batch
exclude '**/*.bat'
exclude '**/*.sh'
//Exclude template textures
exclude '**/*Template.png'
//already excluded from gitignore, but still appear to be included in a locally built jar
exclude '**/desktop.ini'
exclude '**/Thumbs.db'
exclude '**/.DS_Store'
}
processTestResources {
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
} into sourceSets.test.output.resourcesDir
println(sourceSets.test.output.resourcesDir)
}
//--- Core Jar Generation
// Create a core jar, sign it and place it inside the main jar
if(ii_generateCoreJar=='true')
apply from: rootProject.file('gradle/corejar.gradle')
//--- IE Addon
apply from: rootProject.file('gradle/ieaddon.gradle')
if(ii_enableSigning.asBoolean())
apply from: rootProject.file('gradle/codesign.gradle')
tasks.build.doLast(){
if(ii_printSourceSets.toBoolean())
logger.log(LogLevel.WARN, 'Build Location: '+file("./build/libs/").getPath())
}
if(ii_enableSigning.asBoolean()) {
tasks.build.finalizedBy() {
signMainJar
}
}
//--- Help Function
tasks.register('modSetupDocs') {
group = "Help"
description = "Displays the Mod Build Script documentation"
doLast {
printDocs("setup")
}
}