1
1
import groovy.json.JsonSlurper
2
- import org.gradle.internal.os.OperatingSystem
2
+ import java.nio.charset.StandardCharsets
3
3
4
4
5
5
buildscript {
6
6
ext{
7
- // Mindustry API version you want to use
8
- mindustryVersion = " v126.2"
9
-
10
- // Junit version for tests outside a server
11
- junitVersion = " 5.7.2"
12
-
7
+ // Properties
8
+ mindustryVersion = property(" props.mindustry-version" )
9
+ serverDirectoryPath = property(" props.mindustry-server-directory" )
13
10
// Plugin metadata extracted from plugin.json
14
11
metadata = new JsonSlurper (). parseText(file(" $rootDir /plugin.json" ). text)
15
-
16
- // A string that points directly to your server.jar directory
17
- serverDirectoryPath = null
18
-
19
- // the file:// at the beginning is required if you use windows if you don't want github actions to scream at you
20
- if (System . getProperty(" user.name" ) == " Finley" ){
21
- serverDirectoryPath = " file://C:/Users/Finley/Documents/My Games/Mindustry/Server/mindustry-server-$mindustryVersion "
22
- }
23
12
}
24
13
25
14
repositories{
@@ -40,7 +29,7 @@ plugins{
40
29
}
41
30
42
31
43
- group " fr.xpdustry "
32
+ group property( " props.project-group " )
44
33
version metadata. version
45
34
46
35
@@ -50,56 +39,58 @@ repositories{
50
39
}
51
40
52
41
dependencies {
42
+ // Json
43
+ implementation " com.google.code.gson:gson:2.8.8"
44
+ testImplementation " com.google.code.gson:gson:2.8.8"
45
+
53
46
// Mindustry
54
47
compileOnly " com.github.Anuken.Arc:arc-core:$mindustryVersion "
55
48
compileOnly " com.github.Anuken.Mindustry:core:$mindustryVersion "
56
49
57
50
// Unit Testing
58
51
testImplementation " com.github.Anuken.Arc:arc-core:$mindustryVersion "
59
52
testImplementation " com.github.Anuken.Mindustry:core:$mindustryVersion "
60
- testImplementation " org.junit.jupiter:junit-jupiter-params:$j unitVersion "
61
- testImplementation " org.junit.jupiter:junit-jupiter-api:$j unitVersion "
62
- testRuntimeOnly " org.junit.jupiter:junit-jupiter-engine:$j unitVersion "
53
+ testImplementation " org.junit.jupiter:junit-jupiter-params:5.8.1 "
54
+ testImplementation " org.junit.jupiter:junit-jupiter-api:5.8.1 "
55
+ testRuntimeOnly " org.junit.jupiter:junit-jupiter-engine:5.8.1 "
63
56
}
64
57
65
58
59
+ java {
60
+ withSourcesJar()
61
+ }
62
+
66
63
compileJava {
67
- sourceCompatibility = JavaVersion . VERSION_15
68
- targetCompatibility = JavaVersion . VERSION_15
69
- options. encoding = " UTF-8 "
64
+ sourceCompatibility = JavaVersion . VERSION_16
65
+ targetCompatibility = JavaVersion . VERSION_16
66
+ options. encoding = StandardCharsets . UTF_8
70
67
}
71
68
72
- java {
73
- withSourcesJar()
69
+ test {
70
+ useJUnitPlatform()
71
+ }
72
+
73
+ compileTestJava {
74
+ options. encoding = StandardCharsets . UTF_8
74
75
}
75
76
77
+
76
78
jar {
79
+ archiveBaseName = project. property(" props.project-name" )
80
+
77
81
// The following line is required
78
82
from configurations. runtimeClasspath. collect{
79
83
it. isDirectory() ? it : zipTree(it)
80
84
}
81
85
82
- from " plugin.json"
83
- }
84
-
85
-
86
- compileTestJava {
87
- options. encoding = " UTF-8"
88
- }
89
-
90
- test {
91
- useJUnitPlatform()
86
+ from " $rootDir /plugin.json"
92
87
}
93
88
94
89
95
90
task moveJar {
96
91
dependsOn jar
97
92
98
93
doLast{
99
- if (serverDirectoryPath == null || serverDirectoryPath. isEmpty()){
100
- throw new GradleException (" serverDirectoryPath is unset" )
101
- }
102
-
103
94
// Deletes all the jar files that begins with the base artifact name
104
95
delete file(" $serverDirectoryPath /config/mods" ). listFiles({
105
96
it. isFile() && it. name. endsWith(" .jar" ) && it. name. startsWith((String ) jar. archiveBaseName. get())
@@ -112,41 +103,31 @@ task moveJar{
112
103
}
113
104
}
114
105
115
- task runServer {
116
- doLast{
117
- if (serverDirectoryPath == null || serverDirectoryPath. isEmpty()){
118
- throw new GradleException (" serverDirectoryPath is unset" )
119
- }
120
-
121
- exec{
122
- OperatingSystem os = OperatingSystem . current()
123
-
124
- workingDir = file(serverDirectoryPath)
125
-
126
- // Open a mindustry server in a new terminal window
127
- if (os. isWindows()){
128
- commandLine = [" cmd" , " /C" , " start" , " run_server.bat" ]
129
- }else if (os. isLinux()){
130
- commandLine = [" sh" , " -c" , " ./run_server.sh" ]
131
- }else {
132
- throw new GradleException (" Unsuported operation, please implement a case for your os" )
133
- }
134
- }
135
- }
106
+ task runServer (type : JavaExec ){
107
+ workingDir = serverDirectoryPath
108
+ classpath = files(" $serverDirectoryPath /server.jar" )
109
+ mainClass = " mindustry.server.ServerLauncher"
110
+ standardInput = System . in
111
+ args = [" host Veins pvp" ]
136
112
}
137
113
138
114
task deployJar {
139
115
dependsOn moveJar
140
116
dependsOn runServer
141
117
}
142
118
143
- // Required if you want to use the Release GitHub action,
144
- task getArtifactPath {
145
- doLast {
146
- println jar . archiveFile . get() . toString()
119
+ // Makes sure the task are only available if the props.mindustry-server-directory is set correctly
120
+ for ( Task serverTask : [moveJar, runServer, deployJar]) {
121
+ serverTask . configure {
122
+ onlyIf{ file(serverDirectoryPath) . exists() }
147
123
}
148
124
}
149
125
126
+ // Required if you want to use the Release GitHub action
127
+ task getArtifactPath {
128
+ doLast{ println jar. archiveFile. get(). toString() }
129
+ }
130
+
150
131
151
132
publishing {
152
133
publications{
@@ -157,7 +138,7 @@ publishing{
157
138
name = metadata. displayName
158
139
artifactId = metadata. name
159
140
description = metadata. description
160
- url = " https://github.com/$metadata . repo "
141
+ url = " https://github.com/$metadata . repo "
161
142
162
143
licenses{
163
144
license{
0 commit comments