-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild-dist.gradle
More file actions
238 lines (224 loc) · 9.38 KB
/
build-dist.gradle
File metadata and controls
238 lines (224 loc) · 9.38 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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/**
* This file is an ugly hack.
* Many non-shared properties are required to publish a release to Maven, and I
* do not like forcing my developers to put very project-specific data under
* their home directory ($HOME/.gradle/gradle.properties... I wouldn't ever
* consider adding it under a Gradle system installation directory).
* Besides, since Gradle has mandated the single supported file name exactly,
* it is impossible to make it clear that we are using it for non-shared
* usage.
* Therefore, this file uses the output jar of the main 'build.gradle' file
* to load 'local.properties'.
* Due to Gradle initialization problems that burn up hours and hours of my
* life, the 'gradle-javaPropFile-plugin-*.jar' file must be written by
* 'build.gradle' before this 'build-dist.gradle' file executes... but there
* are required interdependencies between the files because 'build-dist.gradle'
* needs to publish artifacts generated by 'build.gradle'... Arrrrrrrrrrrg.
* So, although I am entirely dissatisfied with it, you must build the jar
* file first with 'build.gradle', then use this build file afterwards to
* publish to a Maven repository.
*/
assert ext.cpFileTree.files.size() > 0:
'''Due to boot-strapping issue, you must build the jar with 'build.gradle'
before you can use build file 'build-dist.gradle'.
'''
assert ext.cpFileTree.files.size() < 2:
'''Due to boot-strapping issue, you must have just one project jar before
you can use build file 'build-dist.gradle'. Please run 'gradlew clean jar'.
'''
buildscript {
ext.cpFileTree = fileTree(
dir: 'build/libs',
excludes: ['*-sources.jar', '*-javadoc.jar'],
include: 'gradle-javaPropFile-plugin-*.jar'
)
dependencies { classpath cpFileTree }
repositories {
jcenter()
//mavenCentral()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:0.6'
//classpath 'org.codehaus.groovy:groovy-all:2.3.4'
}
}
apply plugin: 'maven'
apply plugin: 'com.admc.javaPropFile'
apply plugin: 'com.jfrog.bintray'
/* ENABLE THIS BLOCK to enable client-side PGP signing for MC or BinTray:
apply plugin: 'signing'
signing {
sign configurations.archives
}
*/
apply from: 'build.gradle'
defaultTasks 'bintrayUpload'
artifacts {
archives sourcesJar
archives javadocJar
}
configurations { deployJars }
propFileLoader.typeCasting=true
propFileLoader.traditionalPropertiesInit()
if (project.hasProperty('mavenRepository.dest.url')) {
def url = project.property('mavenRepository.dest.url')
assert url != null:
'''Property 'mavenRepository.dest.url' may not be null
'''
assert url instanceof URL:
('''Property 'mavenRepository.dest.url' must be of type URL. Is a '''
+ url.class.name + '\n')
if (url.protocol == 'scp') {
repositories { mavenCentral() }
dependencies {
deployJars 'org.apache.maven.wagon:wagon-ssh:latest.milestone'
}
}
}
uploadArchives {
def authMap = [:]
if (project.hasProperty('mavenRepository.dest.username'))
authMap['userName'] = project.property('mavenRepository.dest.username')
if (project.hasProperty('mavenRepository.dest.password'))
authMap['password'] = project.property('mavenRepository.dest.password')
if (project.hasProperty('mavenRepository.dest.privateKey'))
authMap['privateKey'] =
project.property('mavenRepository.dest.privateKey')
repositories.mavenDeployer {
configuration = configurations.deployJars
if (project.hasProperty('signing.keyId'))
beforeDeployment {
MavenDeployment deployment -> signing.signPom(deployment)
}
if (project.hasProperty('mavenRepository.dest.url'))
repository(url: project.property('mavenRepository.dest.url')) {
authentication(authMap)
}
pom.project {
// The hasProperty tests are necessary even for required variables
// because this code is evaluated even if the uploadArchives task
// will never be executed.
if (project.hasProperty('title')) name project.property('title')
if (project.hasProperty('description'))
description project.property('description')
if (project.hasProperty('url')) url project.property('url')
if (project.hasProperty('inceptionYear'))
inceptionYear project.property('inceptionYear')
scm {
if (project.hasProperty('scm.url'))
url project.property('scm.url')
if (project.hasProperty('scm.connection'))
connection project.property('scm.connection')
if (project.hasProperty('scm.tag'))
tag project.property('scm.tag')
}
if (project.hasProperty('org.name')
|| project.hasProperty('org.url')) organization {
if (project.hasProperty('org.name'))
name project.property('org.name')
if (project.hasProperty('org.url'))
url project.property('org.url')
}
licenses {
license {
name 'Apache 2.0'
url 'https://raw.github.com/unsaved/gradle-javaPropFile-plugin/master/doc/LICENSE.txt'
distribution 'repo'
}
}
if (project.hasProperty('developer.name')
|| project.hasProperty('developer.email')) developers {
developer {
if (project.hasProperty('developer.id'))
id project.property('developer.id')
if (project.hasProperty('developer.name'))
name project.property('developer.name')
if (project.hasProperty('developer.email'))
email project.property('developer.email')
}
}
}
}
}
uploadArchives { doFirst {
['title', 'group', 'mavenRepository.dest.url', 'scm.connection',
'scm.url', 'url', 'inceptionYear', 'description'].each {
assert (project.hasProperty(it) && project.property(it) != null
&& project.property(it) != '') :
"""Property '$it' is required by 'uploadArchives' task.
"""
}
['mavenRepository.dest.url', 'scm.url', 'url', 'org.url'].each {
assert project.property(it) != null:
"""Property '$it' may not be null
"""
assert (!project.hasProperty(it)
|| project.property(it) instanceof URL):
("""Property '$it' must be of type URL. Is a """
+ project.property(it).class.name + '\n')
}
} }
bintray {
if (project.hasProperty('bintray.user'))
user = project.property('bintray.user')
if (project.hasProperty('bintray.apikey'))
key = project.property('bintray.apikey')
configurations = ['archives']
//dryRun = true
//publish = false
pkg {
if (project.hasProperty('bintray.repo'))
repo = project.property('bintray.repo')
name = project.property('name')
if (project.hasProperty('bintray.repo.org'))
userOrg = project.property('bintray.repo.org')
desc = project.property('description')
websiteUrl = project.property('url')
issueTrackerUrl = websiteUrl + '/issues'
vcsUrl = project.property('scm.url')
licenses = ['Apache-2.0']
// label values are used for Bintray and Gradle plugin site search
// links. On Gradle plugin site the search links are labeled like #x.
labels = ['gradle', 'properties', 'templating', 'templates']
publicDownloadNumbers = true
// attributes?
version {
// name = Bintree logical version name
if (project.hasProperty('version.description'))
desc = project.property('version.description')
// released = date
if (project.hasProperty('scm.tag'))
vcsTag = project.property('scm.tag')
// Defaults to version without this.
// Since my convention is to tag precisely with version, this
// is unnecessary for me.
attributes = [
'gradle-plugin': "com.admc.javaPropFile:$project.group:$project.name"
]
/* This is for BinTree server-side signing.
* For this to work, you must upload private and public keys to
* BinTree account, and enable signing on the target repository.
* The passphrase is the passphrase that your PGP key tool
* encrypted the private key with.
* To do it client-side instead, comment out the following and
* enable the signing plugin above.
* If 'signing.password' isn't set, there will be no signing.
*/
gpg {
sign = project.hasProperty('signing.password')
passphrase = (project.hasProperty('signing.password')
? project.property('signing.password') : null)
}
}
}
}
bintrayUpload.dependsOn << {
['bintray.user', 'bintray.apikey', 'bintray.repo',
'version.description'].each {
assert (project.hasProperty(it) && project.property(it) != null
&& project.property(it) != '') :
"""Property '$it' is required by 'bintray' task.
"""
}
print '' // Gradle parser can't handle the loop terminating this block.
}