forked from wellsb1/fort_j
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
149 lines (125 loc) · 3.93 KB
/
Copy pathbuild.gradle
File metadata and controls
149 lines (125 loc) · 3.93 KB
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
plugins {
id "java"
id "maven"
}
group = "io.rocketpartners"
version = "1.2.0"
sourceCompatibility = "1.6"
ext {
// Run bash commands.
//
// opts:
// args -- command-line arguments
// captureOutput -- if true, return output (default: false)
// env -- Map of environment variables
// ignoreExitValue -- if true, fail when exit != 0 (default: false)
// quiet -- if true, don't print command-line (default: false)
// workingDir -- working directory
bash = { opts = [:] ->
opts += [
captureOutput: opts.captureOutput == null ? false : opts.captureOutput,
ignoreExitValue: opts.ignoreExitValue == null ? false : opts.ignoreExitValue,
quiet: opts.quiet == null ? false : opts.quiet
]
def output
try {
exec {
if (opts.captureOutput) {
standardOutput = new ByteArrayOutputStream()
output = { -> standardOutput.toString() }
}
ignoreExitValue = opts.ignoreExitValue
opts.env?.each { key, val -> environment key, val }
opts.workingDir && workingDir(opts.workingDir)
commandLine = [ "bash", "-o", "pipefail", "-c", "${opts.args?.trim()} 2>&1" ]
opts.quiet || println(commandLine.join(" "))
}
if (opts.captureOutput) { output() }
} catch (e) {
if (opts.captureOutput) { println(output()) }
throw e
}
}
// Run git commands.
//
// opts:
// args -- command-line args
// defaultValue -- value to return if no output or error
git = { opts=[:] ->
try {
def result = file(".git").exists() ? bash(opts + [args: "git ${opts.args}".trim()]) : ""
result ?: opts.defaultValue
} catch(Exception e) {
if (opts.defaultValue) { return opts.defaultValue }
throw e
}
}
// Get git author.
//
// opts:
// format -- format (default: "%an")
gitGetAuthor = { opts=[:] ->
opts += [format: opts.format ?: "%an", captureOutput: true]
git(opts + [args: "--no-pager show -s --format='${opts.format}'"])?.trim()
}
isReleaseBranch = { opts=[:] ->
opts += [branch: opts.branch ?: project.branch]
opts.branch ==~ /^main$|^master$|^release-.*/
}
archiveRepo = [
url: "https://maven.pkg.github.com/RocketPartners/artifacts",
user: System.env.GHP_USER,
password: System.env.GHP_PASSWORD
]
branch = git(args: "rev-parse --abbrev-ref HEAD", captureOutput: true, ignoreExitValue: false,
defaultValue: "(branch)")?.trim()
!isReleaseBranch() && (project.version += "-$branch-SNAPSHOT")
}
repositories {
mavenLocal()
maven {
url archiveRepo.url
credentials {
username archiveRepo.user
password archiveRepo.password
}
}
mavenCentral()
}
dependencies {
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.5'
compile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.5'
compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.4'
compile (group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.4') {
exclude group: 'com.fasterxml.jackson', module: 'jackson-annotations'
}
}
uploadArchives {
repositories {
mavenDeployer {
repository(url: archiveRepo.url) {
authentication(userName: archiveRepo.user, password: archiveRepo.password)
}
}
}
doFirst {
println "${jar.archiveName} -> ${archiveRepo.url}"
}
}
task tag {
enabled = isReleaseBranch()
doLast {
git args: "config user.name '${gitGetAuthor()}'"
git args: "config user.email ${gitGetAuthor(format: '%ae')}"
git args: "tag -am 'tag ${project.version}' ${project.version}"
}
}
task pushTags {
mustRunAfter uploadArchives
doLast {
git args: "push --tags"
}
}
task publish {
dependsOn uploadArchives, pushTags
}