-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
266 lines (228 loc) · 8.59 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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// This is the build file we use to compile and run Battlecode players.
// We're using Gradle: https://gradle.org/
// Gradle's plugins allow it to automatically generate build scripts
// for different types of code. Here we apply the Java plugin, which provides
// all the tools needed to build player code!
apply plugin: 'java'
// The Kotlin plugin allows us to compile Kotlin, source files
apply plugin: 'kotlin'
// The Scala plugin expands upon the Java plugin, allowing us to compile
// Scala source files.
apply plugin: 'scala'
// These plugins allow for this build script to be compatible with IDEs.
apply plugin: 'idea'
apply plugin: 'eclipse'
// Extra tools from battlecode.
apply plugin: 'battlecode'
// Tell gradle that we want Java 8.
sourceCompatibility = 1.8
targetCompatibility = 1.8
// We override Gradle's defaults for project directory layout.
sourceSets {
main {
scala.srcDirs = ["src"]
kotlin.srcDirs = ["src"]
output.classesDir = "$buildDir/classes"
}
test {
scala.srcDirs = ["test"]
kotlin.srcDirs = ["test"]
output.classesDir = "$buildDir/tests"
}
}
repositories {
// Let Gradle know about our own repository for hosting Battlecode.
maven {
url "http://battlecode-maven.s3-website-us-east-1.amazonaws.com/"
}
// Use the JCenter repo to resolve Scala dependencies.
jcenter()
}
// Mark the client as a special dependency, so that we can handle it separately.
configurations {
client
}
// Download a different version of the client depending on the local OS.
def os = System.getProperty("os.name").toLowerCase()
def clientName = os.startsWith('windows') ? 'battlecode-client-win' :
os.startsWith('mac') ? 'battlecode-client-mac' :
'battlecode-client-linux'
// The dependencies of this project.
dependencies {
// The Battlecode engine.
compile group: 'org.battlecode', name: 'battlecode', version: versions.battlecode
// The Battlecode client.
client group: 'org.battlecode', name: clientName, version: versions.battlecode
compile "org.jetbrains.kotlin:kotlin-stdlib:$versions.kotlin"
// Scala!
compile group: 'org.scala-lang', name: 'scala-library', version: versions.scala
compile group: 'org.scala-lang', name: 'scala-compiler', version: versions.scala
compile group: 'org.scala-lang', name: 'scala-reflect', version: versions.scala
}
// Eclipse specific setup to enable docs and sources, and configure layout.
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
defaultOutputDir = new File(project.buildDir, 'classes-eclipse')
}
}
// IntelliJ settings.
idea {
module {
downloadSources = true
downloadJavadoc = true
}
}
// Default configuration for running matches.
if (!project.hasProperty("teamA")) {
ext.teamA = "examplefuncsplayer"
}
if (!project.hasProperty("teamB")) {
ext.teamB = "examplefuncsplayer"
}
if (!project.hasProperty("maps")) {
ext.maps = "shrine"
}
// Here we define a task. Tasks like this one, 'unpackClient', can be
// executed in the terminal with `./gradlew unpackClient` in Unix or
// `gradlew unpackClient` in Windows.
task unpackClient(type: Copy, dependsOn: configurations.client) {
description 'Downloads the client.'
group 'battlecode'
dependsOn configurations.client
from {
configurations.client.collect {
zipTree(it)
}
}
into 'client/'
}
build.group = 'battlecode'
build.dependsOn('unpackClient')
// Another task. This one accepts three optional parameters, or "properties",
// corresponding to the bots used by the two teams, and the map(s) used in this
// game. These properties can be set in the command line with:
// On windows:
// `gradlew -PteamA=<team A bot> -PteamB=<team B bot> -Pmaps=<comma
// separated list of maps>`
// On OS X and Linux:
// `./gradlew -PteamA=<team A bot> -PteamB=<team B bot> -Pmaps=<comma
// separated list of maps>`
task run(type: JavaExec, dependsOn: 'build') {
description 'Runs a match without starting the client.'
group 'battlecode'
main = 'battlecode.server.Main'
classpath = sourceSets.main.runtimeClasspath
args = ['-c=-']
jvmArgs = [
'-Dbc.server.mode=headless',
'-Dbc.server.map-path=maps',
'-Dbc.server.debug=true',
'-Dbc.engine.debug-methods=true',
'-Dbc.game.team-a='+project.property('teamA'),
'-Dbc.game.team-b='+project.property('teamB'),
'-Dbc.game.team-a.url='+sourceSets.main.output.classesDir,
'-Dbc.game.team-b.url='+sourceSets.main.output.classesDir,
'-Dbc.game.maps='+project.property('maps'),
'-Dbc.server.save-file=' + 'matches/' + project.property('teamA') + '-vs-' + project.property('teamB') + '-on-' + project.property('maps') + '.bc17'
]
}
// Same as above, but with all the logging disabled...
task runQuiet(type: JavaExec, dependsOn: 'build') {
description 'Runs a match without starting the client and without debug logs'
group 'battlecode'
main = 'battlecode.server.Main'
classpath = sourceSets.main.runtimeClasspath
args = ['-c=-']
jvmArgs = [
'-Dbc.server.mode=headless',
'-Dbc.server.map-path=maps',
'-Dbc.server.debug=false',
'-Dbc.engine.debug-methods=false',
'-Dbc.engine.silence-a=true',
'-Dbc.engine.silence-b=true',
'-Dbc.game.team-a='+project.property('teamA'),
'-Dbc.game.team-b='+project.property('teamB'),
'-Dbc.game.team-a.url='+sourceSets.main.output.classesDir,
'-Dbc.game.team-b.url='+sourceSets.main.output.classesDir,
'-Dbc.game.maps='+project.property('maps'),
'-Dbc.server.save-file=' + 'matches/' + project.property('teamA') + '-vs-' + project.property('teamB') + '-on-' + project.property('maps') + '.bc17'
]
}
// This task prints out all available players, in the format that the `run`
// task expects them to be given as.
task listPlayers {
description 'Lists all available players.'
group 'battlecode'
doLast {
sourceSets.main.allSource.each {
if (it.getName().equals('RobotPlayer.java')
|| it.getName().equals('RobotPlayer.kt')
|| it.getName().equals('RobotPlayer.scala')) {
URI base = new File(project.projectDir, 'src').toURI()
URI full = it.toURI()
String path = base.relativize(full).toString()
println 'PLAYER: '+path.substring(0, path.lastIndexOf('/')).replaceAll('/', '.')
}
}
}
}
// This task prints out all available maps, in the format that the `run` task
// expects them to be given as.
task listMaps {
description 'Lists all available maps.'
group 'battlecode'
doLast {
sourceSets.main.compileClasspath.each {
if (it.toString().contains('battlecode-2017')) {
FileCollection fc = zipTree(it)
fc += fileTree(new File(project.projectDir, 'maps'))
fc.each {
String fn = it.getName()
if (fn.endsWith('.map17')) {
println 'MAP: '+fn.substring(0, fn.indexOf('.map17'))
}
}
}
}
}
}
// This task prepares player code for upload, assembling it into a Java archive.
// This archive can be uploaded at `www.battlecode.org`.
task jarForUpload(type: Jar) {
description 'Assembles source code into an archive, ready to be uploaded to the Battlecode site.'
group 'battlecode'
from sourceSets.main.scala.srcDirs
destinationDir = project.projectDir
archiveName = 'battlecode-player-upload.jar'
}
// Battlecode updates a lot.
// We should make sure to check for new dependencies frequently.
configurations.all {
// Check for updates every build.
resolutionStrategy.cacheDynamicVersionsFor 60, 'seconds'
}
// We need to download the battlecode plugin before we can run the build script; this does that.
buildscript {
ext.versions = [
battlecode: '2017.+',
kotlin: '1.0.6',
scala: '2.11.7'
]
repositories {
maven {
url "http://battlecode-maven-test-aaarblgarbl.s3-website-us-east-1.amazonaws.com/"
}
jcenter()
}
dependencies {
// Load the battlecode plugin onto the classpath.
classpath group: 'org.battlecode', name: 'battlecode-gradle-plugin', version: versions.battlecode
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlin"
}
configurations.all {
// Check for updates every build.
resolutionStrategy.cacheDynamicVersionsFor 60, 'seconds'
}
}