-
Notifications
You must be signed in to change notification settings - Fork 39
/
build.gradle
199 lines (165 loc) · 5.58 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
import org.apache.tools.ant.taskdefs.condition.Os
import java.text.SimpleDateFormat
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'
apply plugin: 'rpm'
sourceCompatibility = 1.7
targetCompatibility = 1.7
//use Gradle Wrapper to control which version of Gradle is used (for plugin compatibility)
task wrapper(type: Wrapper) {
gradleVersion = '1.7'
}
repositories {
mavenCentral()
}
dependencies {
compile ("com.yammer.dropwizard:dropwizard-core:0.6.2") {
exclude group: 'org.eclipse.jetty.orbit'
}
compile "org.apache.geronimo.specs:geronimo-servlet_3.0_spec:1.0"
compile 'org.projectlombok:lombok:0.11.6'
compile "org.springframework:spring-web:$springVersion"
compile "javax.inject:javax.inject:1"
compile "org.springframework.security:spring-security-web:$springSecurityVersion"
compile "org.springframework.security:spring-security-config:$springSecurityVersion"
compile "org.springframework.security:spring-security-aspects:$springSecurityVersion"
}
jar {
manifest {
attributes 'Main-Class': 'com.github.jacek99.myapp.MyAppService'
attributes 'Implementation-Title': 'MyApp' ,'Implementation-Version': version
}
}
/**
* Gradle Shadow plugin integration
*/
buildscript {
repositories {
maven {
name 'Gradle Shadow'
url 'http://dl.bintray.com/content/johnrengelman/gradle-plugins'
}
mavenCentral()
}
dependencies {
classpath 'org.gradle.plugins:shadow:0.7.4'
classpath 'com.trigonic:gradle-rpm-plugin:1.4'
}
}
ext {
release = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())
}
apply plugin: 'shadow'
task run(dependsOn: 'classes', type: JavaExec) {
main = 'com.github.jacek99.myapp.MyAppService'
classpath = sourceSets.main.runtimeClasspath
args 'server','myapp.yml'
}
task runShadow(type:Exec, dependsOn: 'shadow') {
workingDir = "build/libs"
commandLine = ['java', '-jar', '-server', "myapp-$version-shadow.jar",'server','../../myapp.yml']
}
task bdd(type: Exec, dependsOn: 'shadow') {
description = "Tests BDDs against the running application"
// fix to run cucumber on a particular infernal OS properly
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine 'cmd', '/c', 'bundle.bat', 'exec', 'cucumber'
}
else {
commandLine = ['cucumber']
}
workingDir = "./src/test/resources/bdd"
def oneJarProcess = null
doFirst{
println "Starting application on separate thread..."
Thread.startDaemon {
oneJarProcess = "java -jar -server build/libs/myapp-$version-shadow.jar server myapp.yml".execute()
}
println "Waiting for application to start before executing tests..."
addShutdownHook {
println "Shutting down application"
oneJarProcess.destroy()
}
}
}
/**
* NATIVE LINUX PACKAGING SUPPORT
*/
/**
* DEBIAN / RPM integration
*/
task deb(dependsOn: 'shadow') << {
//define full Debian package name and version number
ext.debian = "myapp-${version}-${project.ext.release}"
copy {
from "src/deploy/resources/config"
from "src/deploy/resources/upstart/debian"
into "build/distributions/$debian"
}
copy {
from "src/deploy/resources/deb"
into "build/distributions/$debian/DEBIAN"
}
copy {
from("build/libs") {
include "myapp-$version-shadow.jar"
//remove version number from actual file installed on a server, removes need to update myapp.conf every time
rename { String fileName ->
fileName.replace("-$version", '')
}
}
into "build/distributions/$debian/opt/myapp"
}
//replace version in Debian control file
println "Updating version in Debian control file"
String contents = file(new File( "build/distributions/$debian/DEBIAN/control" )).getText( 'UTF-8')
contents = contents.replaceAll( '##VERSION##', "$version")
file(new File("build/distributions/$debian/DEBIAN/control")).write(contents,'UTF-8')
println "Compiling ${debian}.deb using Debian packaging tools..."
exec {
commandLine = ['dpkg-deb',"--build","$debian"]
workingDir = "build/distributions"
}
}
task rpm(type: Rpm, dependsOn: 'shadow') {
packageName = 'myapp'
version = "$version"
release = project.ext.release
arch = NOARCH
os = LINUX
summary = "MyApp"
description 'Dropwizard sample app'
vendor = 'Jacek Furmankiewicz'
url = 'https://github.com/jacek99'
//installUtils = file('scripts/rpm/utils.sh')
//preInstall = file('scripts/rpm/preInstall.sh')
postInstall = file('src/deploy/resources/rpm/postinst')
preUninstall = file('src/deploy/resources/rpm/prerm')
//postUninstall = file('scripts/rpm/postUninstall.sh')
requires('java-1.7.0-openjdk', '1.7', GREATER | EQUAL)
into '/opt/myapp'
//application executable
from("build/libs") {
include "myapp-$version-shadow.jar"
//remove version from file to avoid having to redo config files on every release
rename { String fileName ->
fileName.replace("-$version", '')
}
}
//configuration file
from('src/deploy/resources/config') {
fileType = CONFIG
into '/'
}
//systemd configuration for Fedora
from('src/deploy/resources/systemd') {
fileType = CONFIG
into '/'
}
//Upstart file for CentOS/RHEL, customized compared to the Debian version
from('src/deploy/resources/upstart/centos') {
fileType = CONFIG
into '/'
}
}