forked from chatty/chatty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
140 lines (105 loc) · 3.65 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
import java.util.regex.Matcher
plugins {
id "com.github.johnrengelman.shadow" version "1.2.3"
}
apply plugin: 'java'
// This seems to fix non-ASCII characters in the code not appearing correctly after compiling
compileJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8
// Tells Netbeans what the main class is
ext.mainClass = 'chatty.Chatty'
archivesBaseName = 'Chatty'
repositories {
mavenCentral()
}
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
}
}
test {
java {
srcDirs = ['test']
}
resources {
srcDirs = ['test']
}
}
}
// Method that gets the version name from Chatty.java. It's defined after the sourceSets block because it uses its path
def extractVersion = { ->
File chattyClassFile = new File((File) sourceSets.main.java.srcDirs.first(), 'chatty/Chatty.java');
// Use this regex to extract the version from the file
Matcher matcher = chattyClassFile.text =~ /(?m)^\s*public static final String VERSION = "(.*)";\s*$/
// From the first matching line, return the first capture (the version)
return matcher[0][1]
}
version = extractVersion()
dependencies {
// Take the .jar files from the assets/lib directory and add them to the compile-time classpath
compile fileTree(dir: 'assets/lib', include: ['*.jar'])
testCompile 'junit:junit:4.12'
}
// The wrapper is a small batch/bash script that can be used to run Gradle on machines where it hasn't been directly
// installed. It allows you to specify the project's Gradle version for everyone that has checked out the project.
wrapper {
gradleVersion = '2.13'
}
jar {
archiveName = "${archivesBaseName}.jar"
manifest {
attributes(
'Main-Class': mainClass,
)
}
}
// Builds a jar that includes not only the compiled files from this project, but also the .class files from the
// dependencies. This removes the need for a separate 'libs' directory when Chatty is installed.
shadowJar {
// A suffix for the release jar name. By default this is '-all', which gives a name like 'Chatty-v0.8.3b3-all.jar'
classifier = null
version = null
manifest {
inheritFrom project.tasks.jar.manifest
}
}
// The following are a series of tasks for building the release artifacts. They are bundled into zip files and placed
// in the 'build/releases' directory.
def releasesDir = new File(buildDir, 'releases')
task allPlatformsZip(type: Zip, group: 'build') {
dependsOn shadowJar
from tasks.shadowJar.archivePath
from ('assets') {
exclude 'lib'
}
destinationDir = releasesDir
archiveName = "${archivesBaseName}_${version}.zip"
}
task hotkey32Zip(type: Zip, group: 'build') {
dependsOn shadowJar
with allPlatformsZip
from 'assets/lib/dlls/JIntellitype32.dll'
rename { filename -> filename.replaceAll('JIntellitype\\d{2}', 'JIntellitype') };
destinationDir = releasesDir
archiveName = "${archivesBaseName}_${version}_hotkey_32bit.zip"
}
task hotkey64Zip(type: Zip, group: 'build') {
dependsOn shadowJar
with allPlatformsZip
from 'assets/lib/dlls/JIntellitype64.dll'
rename { filename -> filename.replaceAll('JIntellitype\\d{2}', 'JIntellitype') };
destinationDir = releasesDir
archiveName = "${archivesBaseName}_${version}_hotkey_64bit.zip"
}
// Builds all the release zips
task releaseZips(group: 'build') {
dependsOn allPlatformsZip, hotkey32Zip, hotkey64Zip
}
// Builds the full project, runs the unit tests and packages the release zips.
task release(group: 'build') {
dependsOn releaseZips, build
}