forked from opensha/opensha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-common.gradle
209 lines (194 loc) · 6.51 KB
/
build-common.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
198
199
200
201
202
203
204
205
206
207
208
209
/*
* Global build file used by all OpenSHA subprojects.
* Declares common fields and tasks.
*
* This file requires that the 'parentProject' property be defined (should be null for top level project)
*/
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
compileJava.options.encoding = "UTF-8"
repositories {
mavenCentral()
maven {
url "https://code.usgs.gov/api/v4/groups/1352/-/packages/maven"
name "NSHMP GitLab Group"
}
}
configurations {
apiResolvable {
description 'resolvable view of the api classpath'
canBeResolved=true
extendsFrom api
}
}
configurations {
implResolvable {
description 'resolvable view of the implementation classpath'
canBeResolved=true
extendsFrom implementation
}
}
ext.getDate = {
new Date().format('yyyy_MM_dd')
}
logger.info('running settings with project='+project.name+' and rootProject.name='+rootProject.name)
if (project.parentProject != null) {
logger.info(project.name+" is a child of: "+project.parentProject)
apply from: '../opensha/build-git.gradle'
} else {
logger.info(project.name+" is top level")
apply from: 'build-git.gradle'
}
if (project.parentProject != null) {
jar {
// include version files
from(project(':opensha').projectDir) {
include 'build.version'
}
from(project.projectDir) {
include 'build.githash'
include 'build.gitbranch'
include 'build.gitremoteurl'
include 'build.date'
}
}
logger.info('Defining fatJar task in '+project.name+" that depends on "+project.parentProject)
task fatJar(type: Jar, dependsOn: ':'+project.parentProject+':fatJar') {
doFirst {
writeBuildFiles()
}
archiveBaseName = project.name + '-all'
// include all 'api' dependencies
from {
configurations.apiResolvable.collect { it.isDirectory() ? it : zipTree(it).matching {
exclude { it.path.contains('META-INF') }
}}
}
// include compiled source from this project
from sourceSets.main.allJava
// include upstream project fat jar
from zipTree(file('../'+project.parentProject+'/build/libs/'+project.parentProject+'-all.jar')).matching {
exclude 'build.githash'
exclude 'build.gitbranch'
exclude 'build.gitremoteurl'
exclude 'build.date'
}
duplicatesStrategy = 'exclude'
with jar
}
} else {
jar {
// include version files
from(project.projectDir) {
include 'build.version'
include 'build.githash'
include 'build.gitbranch'
include 'build.gitremoteurl'
include 'build.date'
}
}
task fatJar(type: Jar) {
doFirst {
writeBuildFiles()
}
doLast {
delete new File(projectDir, "build.githash")
delete new File(projectDir, "build.gitbranch")
delete new File(projectDir, "build.gitremoteurl")
delete new File(projectDir, "build.date")
}
archiveBaseName = project.name + '-all'
// include all 'api' dependencies
from {
configurations.apiResolvable.collect { it.isDirectory() ? it : zipTree(it).matching {
exclude { it.path.contains('META-INF') }
}}
}
// include compiled source from this project
from sourceSets.main.allJava
duplicatesStrategy = 'exclude'
with jar
}
}
void createAppTask(String taskName, String prefix, String mainClass) {
// old default prefix was: prefix+'-'+getDate()+'-'+getGitHash()
if (project.parentProject != null) {
task (taskName, type: Jar, dependsOn: ':'+project.parentProject+':fatJar') {
doFirst {
writeBuildFiles()
}
archiveBaseName = prefix
from { configurations.apiResolvable.collect {
it.isDirectory() ? it : zipTree(it).matching {
exclude { it.path.contains('META-INF') }
}
}}
// include compiled source from this project
from sourceSets.main.allJava
// include upstream project fat jar
from zipTree(file('../'+project.parentProject+'/build/libs/'+project.parentProject+'-all.jar')).matching {
exclude 'build.githash'
exclude 'build.gitbranch'
exclude 'build.gitremoteurl'
exclude 'build.date'
exclude { it.path.contains('META-INF') }
}
// include version files
from(project(':opensha').projectDir) {
include 'build.version'
}
from(project.projectDir) {
include 'build.githash'
include 'build.gitbranch'
include 'build.gitremoteurl'
include 'build.date'
}
manifest {
attributes(
'Class-Path': configurations.apiResolvable.collect { it.getName() }.join(' '),
'Main-Class': mainClass
)
}
duplicatesStrategy = 'exclude'
with jar
}
} else {
task (taskName, type: Jar) {
doFirst {
writeBuildFiles()
}
archiveBaseName = prefix
from { configurations.apiResolvable.collect {
it.isDirectory() ? it : zipTree(it).matching {
exclude { it.path.contains('META-INF') }
}
}}
// include compiled source from this project
from sourceSets.main.allJava
// include version files
from(project.projectDir) {
include 'build.version'
}
from(project.projectDir) {
include 'build.githash'
include 'build.gitbranch'
include 'build.gitremoteurl'
include 'build.date'
}
manifest {
attributes(
'Class-Path': configurations.apiResolvable.collect { it.getName() }.join(' '),
'Main-Class': mainClass
)
}
duplicatesStrategy = 'exclude'
with jar
}
}
}
// make that method visible
ext {
createAppTask = this.&createAppTask
}