-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
112 lines (94 loc) · 3.34 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
subprojects {
apply plugin: 'java'
group 'org.blockserver'
buildDir = "${project.rootDir}/build/${project.name}"
sourceSets {
main {
java.srcDir('/src/main/java');
resources.srcDir('/src/main/resources');
}
test {
java.srcDir('/src/test/java');
resources.srcDir('/src/test/resources');
}
}
jar {
archiveName = "${baseName}.${extension}";
if (hasProperty('buildPath'))
destinationDir = new File(rootDir.toString() + getProperty('buildPath').toString());
else
destinationDir = new File("${rootDir}/Server");
from{ getDependencyClasses() };
}
task setupProperties() {
group = 'setup'
description = 'Adds defaults to property files.'
doLast {
Properties properties = takeProperties(it.getProject());
addDefaultProperty(properties, 'version', '1.0');
addDefaultProperty(properties, 'buildNumber', '1');
storeProperties(it.getProject(), properties);
}
}
task build {
dependsOn 'setupProperties'
doLast {
Properties properties = takeProperties(it.getProject());
if (!isNumber(properties.getProperty('buildNumber')))
throw new GradleException("\'buildNumber\' must be a double!");
properties.setProperty('buildNumber', incrementNumber(properties.getProperty('buildNumber')));
println 'New Build: ' + properties.getProperty('buildNumber');
storeProperties(it.getProject(), properties);
}
}
}
project(':Core') {
jar {
manifest.attributes('Main-Class': 'org.blockserver.core.Run')
}
task run(type: JavaExec, dependsOn: 'buildVersion') {
classpath = files("Server")
main = "org.blockserver.core.Run"
}
}
def takeProperties(Project project) {
File propertiesFile = new File("${project.projectDir}/gradle.properties")
if (!propertiesFile.exists())
propertiesFile.createNewFile();
Properties properties = new Properties();
properties.load(propertiesFile.newReader());
return properties;
}
def addDefaultProperty(Properties properties, Object key, Object defaultProperty) {
if (!properties.containsKey(key.toString()))
properties.setProperty(key.toString(), defaultProperty.toString());
}
def storeProperties(Project project, Properties properties) {
properties.store(new File("${project.projectDir}/gradle.properties").newWriter(), null);
}
def incrementNumber(Object number) {
if (!isNumber(number))
return number.toString();
return ((number as Double) + 1).toString();
}
def isNumber(Object object) {
return object.toString().matches("-?\\d+(\\.\\d+)?")
}
def getDependencyClasses() {
int added = 0;
int skipped = 0;
// println 'Adding specified dependencies to jar:'
if (!getConfigurations().contains('compile'))
return [];
List dependencyClasses = getConfigurations().getByName('compile').collect({
if (!it.getName().endsWith('.jar')) {
skipped++;
return [];
}
// println '/t' + it.getName().replace('.jar', '');
added++;
return zipTree(it);
});
// println 'Completed(Added: ' + added + ' Skipped:' + skipped + ')';
return dependencyClasses;
}