-
Notifications
You must be signed in to change notification settings - Fork 44
/
build.gradle
240 lines (220 loc) · 6.82 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
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
239
240
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id 'java'
id 'maven-publish'
id "com.github.node-gradle.node" version "7.0.1"
id 'com.github.gmazzo.buildconfig' version '3.0.3'
}
subprojects {
afterEvaluate {
java.sourceCompatibility = JavaVersion.VERSION_11
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
maven {
name = 'ZK Repository'
url = uri('https://mavensync.zkoss.org/maven2')
}
maven {
name = 'ZK Evaluation Repository'
url = uri('https://mavensync.zkoss.org/eval')
}
}
publishing {
publications {
"$project.name"(MavenPublication) {
groupId = "${group}"
artifactId = project.name
// pom configuration
pom {
name = project.description
url = "https://www.zkoss.org/$project.name"
description = project.description
licenses {
license {
name = 'GNU LESSER GENERAL PUBLIC LICENSE, Version 3'
url = 'https://www.gnu.org/licenses/lgpl.html'
distribution = 'repo'
}
}
developers {
developer {
id = 'zkteam'
name = 'ZK Team'
email = '[email protected]'
url = 'https://www.zkoss.org'
organization = 'Potix'
organizationUrl = 'https://www.zkoss.org'
roles = ['architect', 'developer']
timezone = '8'
properties = [
picUrl: 'https://www.zkoss.org'
]
}
}
scm {
connection = 'scm:git:https://github.com/zkoss/zk.git'
url = 'https://mavensync.zkoss.org/maven2'
}
withXml {
// add repositories in generated pom
def repositoriesNode = asNode().appendNode('repositories')
project.repositories.each { repository ->
if (repository instanceof MavenArtifactRepository && repository.name != 'MavenRepo' && repository.name != 'MavenLocal') {
def repositoryNode = repositoriesNode.appendNode('repository')
repositoryNode.appendNode('id', repository.name)
repositoryNode.appendNode('url', repository.url)
}
}
}
}
// add dependencies to pom
from(components.java)
suppressAllPomMetadataWarnings()
}
}
}
// move & rename default-pom.xml
task preparePomFile(type: Copy) {
dependsOn(rootProject.tasks.withType(GenerateMavenPom))
into file("$projectDir/build/pom")
from file("$rootDir/build/publications/$project.name")
include '**/pom-default.xml'
rename 'pom-default.xml', 'pom.xml'
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
// Compile LESS
task compileLess() {
setOnlyIf { project.ext['gradleFrontendSkip'] == 'false' }
dependsOn(npmInstall)
if (new File("$projectDir/src/main/resources/web/$project.name/").exists()) {
inputs.dir("$projectDir/src/main/resources/web/$project.name/")
outputs.dir("$projectDir/codegen/resources/web/$project.name/")
doLast {
exec {
def lessOpts = System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows') ? '{\\\"javascriptEnabled\\\":true}' : '{"javascriptEnabled": true}'
commandLine "$rootDir/node_modules/.bin/zklessc", '-s', "$projectDir/src/main/resources/web/${project.name}", '-o', "$projectDir/codegen/resources/web/${project.name}", '-c', '--less-opts', lessOpts
}
}
}
}
// Configure additional resource for generated resources
processResources() {
dependsOn(compileLess)
from("codegen/resources") {
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
// replace @version@ token in xml files
from('src/main/resources') {
include "**/config.xml", "**/lang.xml", "**/lang-addon.xml"
filter(ReplaceTokens, tokens: [version: "$version".toString()]) // Gstring to String
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
}
jar {
exclude "**/*.less", "**/less/**"
manifest {
attributes(
"Build-Jdk-Spec": JavaVersion.current(),
"Created-By": 'Gradle ' + project.getGradle().getGradleVersion()
)
}
}
// build sources jar for bundle
task sourcesJar(type: Jar) {
dependsOn(generateBuildConfig)
archiveClassifier = 'sources'
// add generated java in to source
from "$buildDir/generated/source/buildConfig/main/main"
includeEmptyDirs false
from 'src/main/java'
from('src/main/resources') {
exclude '**/metainfo'
include '**/*.less'
}
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
// combine jar & pom.xml into one bundle.jar for release theme
task bundleJar(type: Jar) {
dependsOn 'jar'
dependsOn 'sourcesJar'
dependsOn 'preparePomFile'
archiveClassifier = "bundle"
def elementName = "${project.name}-${project.version}"
from "$buildDir/pom"
from("$buildDir/libs") {
include "**/${elementName}.jar"
include "**/${elementName}-sources.jar"
setDuplicatesStrategy(DuplicatesStrategy.INCLUDE)
}
}
// build zip for release zk
task zip(type: Zip) {
dependsOn 'jar'
dependsOn 'sourcesJar'
archiveFileName = "${project.name}-${project.version}.zip"
destinationDirectory = file("$buildDir/zip")
from("$buildDir/libs/${project.name}-${project.version}.jar") {
rename "${project.name}-${project.version}.jar", "${project.name}.jar"
}
from("$buildDir/libs/${project.name}-${project.version}-sources.jar") {
rename "${project.name}-${project.version}-sources.jar", "${project.name}-sources.jar"
}
from "$projectDir/readme.txt"
}
task release() {
dependsOn 'bundleJar'
dependsOn 'zip'
doLast {
copy {
from "$buildDir/zip/${project.name}-${project.version}.zip"
into "$buildDir/dist"
}
copy {
from "$buildDir/libs/${project.name}-${project.version}-bundle.jar"
into "$buildDir/dist/maven"
}
copy {
from "$buildDir/libs/${project.name}-${project.version}-bundle.jar"
into "$rootDir/build/dist/theme"
rename "${project.name}-${project.version}-bundle.jar", "${project.name}.jar"
}
copy {
from "$buildDir/libs/${project.name}-${project.version}-bundle.jar"
into "$rootDir/build/theme/maven"
}
copy {
from "$buildDir/zip/${project.name}-${project.version}.zip"
into "$rootDir/build/theme"
}
}
}
// Delete codegen folder before clean
clean.doFirst {
delete "$projectDir/codegen/"
}
}
}
task release() {
dependsOn subprojects.collect { ":$it.name:release" }
}
// change all the version in gradle.properties under zkthemes
// e.g. ./gradlew upVer -PchangeVersionTo=10.0.1-SNAPSHOT
task upVer() {
doLast {
if (project.hasProperty("changeVersionTo")) {
fileTree("$rootDir/").matching {
include "**/gradle.properties"
}.each { file ->
println "upVer: ${file.path} from ${project.version} to ${project.changeVersionTo}"
ant.replaceregexp(
file: file,
match: "version=$project.version",
replace: "version=$project.changeVersionTo",
)
}
}
}
}