forked from MascusJeoraly/LanguageUtils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
241 lines (212 loc) · 6.43 KB
/
build.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/**
* author: Barteks2x
* Edited
**/
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'
group = 'com.meowj'
archivesBaseName = 'LangUtils'
version = '1.5.0'
final def EULA_ACCEPT = true
final def BUKKIT_ARGS = []
final def BUKKIT_VERSION = '1.9.4-R0.1-SNAPSHOT'
final def LINUX_TERMINAL_COMMAND = ''
final def LINUX_TERMINAL_ARGS = ['-e']
//args for some terminal emulators:
//xfce4-terminal, terminator: ['-x']
//konsole, roxterm, Eterm, rxvt, lxterminal: ['-e']
//tilda, guake and yakuake, gnome-terminal: didn't work
final def SERVER_DIR = 'run/'
final def PLUGINS_DIR = SERVER_DIR + 'plugins/'
final def OUT_DIR = 'build/libs/'
final def OS_NAME = System.getProperty("os.name").toLowerCase()
final def IS_WINDOWS = OS_NAME.contains('win')
final def IS_LINUX = OS_NAME.contains('linux')
final def IS_MAC = OS_NAME.contains('mac')
sourceCompatibility = '1.7'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
//noinspection GroovyAssignabilityCheck
processResources {
from(sourceSets.main.resources.srcDirs) {
exclude 'plugin.yml'
}
from(sourceSets.main.resources.srcDirs) {
include 'plugin.yml'
expand 'version': project.version
}
}
def cfgOsSpecific = {
//hack to workaround gradle bug: https://issues.gradle.org/browse/GRADLE-2462
if (IS_WINDOWS) {
//start server in cmd window
executable 'cmd'
jvmArgs '/K'
jvmArgs 'start'//without this new window won't be created
jvmArgs 'java'
} else if (IS_LINUX) {
//on linux it seems to work correctly
if (!LINUX_TERMINAL_COMMAND.isEmpty()) {
executable LINUX_TERMINAL_COMMAND
for (arg in LINUX_TERMINAL_ARGS) {
jvmArgs arg
}
jvmArgs 'java'
}
} else if (IS_MAC) {
println "It may not work correctly on mac... "
} else {
println "Unknown OS: " + OS_NAME
}
}
/**
* Set up classpath, working directory and arguments
*/
def runCfgPre = {
configure cfgOsSpecific
workingDir = SERVER_DIR
classpath = sourceSets.main.runtimeClasspath
main = 'org.bukkit.craftbukkit.Main'
// jvmArgs JAVA_ARGS
args(BUKKIT_ARGS)
classpath = classpath.filter { File file ->
!file.absolutePath.replace('\\', '/').contains('/build/') && //generated class files
!file.name.contains(archivesBaseName) && //generated jar
!file.name.contains("spigot-api") && //spigot api jar, spigot server jar contains it
!(file.name.toLowerCase().contains("bukkit") && !file.name.toLowerCase().contains('craftbukkit')) //bukkit api jar, craftbukkit jar contains it
}
ignoreExitValue = true
enableAssertions = true
}
def acceptEula = {
if (!EULA_ACCEPT) {
throw new Error('Minecraft EULA not accepted! Change EULA_ACCEPT to true to accept Minecraft EULA.')
}
//automatically accept eula
File eulaFile = file(SERVER_DIR + 'eula.txt')
if (eulaFile.isDirectory()) {
eulaFile.deleteDir()
}
if (!eulaFile.exists()) {
eulaFile.getParentFile().mkdirs()
eulaFile.createNewFile()
}
eulaFile.text = 'eula=' + EULA_ACCEPT
}
def createPluginsDir = {
//make sure that plugins directory exists
File pluginsFolder = file(PLUGINS_DIR)
if (pluginsFolder.exists() && !pluginsFolder.isDirectory()) {
delete pluginsFolder
assert !pluginsFolder.exists()
}
if (!pluginsFolder.exists()) {
pluginsFolder.mkdirs()
assert pluginsFolder.exists() && pluginsFolder.isDirectory()
}
}
def copyPlugin = {
//copy the plugin to plugins folder
String jarName = archivesBaseName + '-' + version + '.jar'
if (OS_NAME.contains('linux')) {
File from = file(OUT_DIR + jarName)
File to = file(PLUGINS_DIR + jarName)
exec {
//on linux we can create symlink
executable 'ln'
args = ["-s", from, to]
}
} else {
//on windows (and mac?) we need to copy...
copy {
from OUT_DIR
into PLUGINS_DIR
include jarName
}
}
}
/**
* Set up server workspace (copy plugin, accept eula...
*/
def runCfg = {
configure acceptEula
configure createPluginsDir
configure copyPlugin
}
/**
* Run and debug tasks. Without diFirst ther are started before evaluation (at least in Netbeans)
*/
task run(type: JavaExec, dependsOn: build) {
doFirst {
configure runCfgPre
configure runCfg
standardInput = System.in
}
}
task debug(type: JavaExec, dependsOn: build) {
debug = true
doFirst {
configure runCfgPre
configure runCfg
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact sourcesJar
artifact javadocJar
}
}
repositories {
maven {
url "$buildDir/repo"
}
}
}
/**
* Delete previous versions of the plugin from plugins folder.
* Don't delete other plugins to allow installing other plugins.
*/
task cleanUpPluginsDir << {
if (!file(PLUGINS_DIR).exists()) {
println 'Nothing to delete!'
return
}
println 'Deleting old plugin...'
ant.delete(includeEmptyDirs: 'false') {
fileset(dir: file(PLUGINS_DIR), includes: archivesBaseName + '*.jar')
}
}
compileJava.dependsOn cleanUpPluginsDir
build.dependsOn sourcesJar, javadocJar
repositories {
mavenCentral()
mavenLocal()
maven {
url 'https://hub.spigotmc.org/nexus/content/groups/public/'
}
maven {
url 'https://oss.sonatype.org/content/groups/public/'
}
}
//noinspection GroovyAssignabilityCheck
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.10'
testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.6.2'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.6.2'
//Bukkit API and libraries
compile group: 'org.spigotmc', name: 'spigot-api', version: BUKKIT_VERSION
//other libs
//Craftbukkit server(not available on maven repo)
runtime files('run/Server.jar')//You should have a spigot in the run/ dir to use "run" command
}