-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathbuild.gradle
262 lines (237 loc) · 6.77 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id 'java-library'
id 'maven-publish'
id "com.github.node-gradle.node" version "7.0.1"
id 'com.github.gmazzo.buildconfig' version '3.0.3'
id 'idea'
}
idea {
module {
outputDir file("$buildDir/classes/main")
testOutputDir file("$buildDir/classes/test")
}
}
repositories {
mavenCentral()
maven {
name = 'ZK CE Repository'
url = uri('https://mavensync.zkoss.org/maven2')
}
maven {
name = 'ZK PE EE Evaluation'
url = uri('https://mavensync.zkoss.org/eval')
}
}
java {
// Declaring feature variants for optionalImplementation, to generate dependency optional in pom
registerFeature('optional') {
usingSourceSet(sourceSets.main)
}
}
def zkEvalVersion = "9.6.0-Eval"
dependencies {
optionalImplementation "org.zkoss.common:zcommon:${zkEvalVersion}"
optionalImplementation "org.zkoss.zk:zk:${zkEvalVersion}"
optionalImplementation "org.zkoss.zk:zul:${zkEvalVersion}"
optionalImplementation "org.zkoss.zk:zkex:${zkEvalVersion}"
optionalImplementation "org.zkoss.zk:zkmax:${zkEvalVersion}"
}
description = 'The Atlantic Theme'
java.sourceCompatibility = JavaVersion.VERSION_11
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
buildConfig {
className = 'Version'
packageName = "org.zkoss.theme.${project.name}"
buildConfigField("String", "UID", provider { "\"${project.version}\"" })
}
publishing {
publications {
atlantic(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') {
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(type: Exec) {
setOnlyIf { project.ext['gradleFrontendSkip'] == 'false' }
dependsOn(npmInstall)
def lessOpts = System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows') ? '{\\\"javascriptEnabled\\\":true}' : '{"javascriptEnabled": true}'
commandLine "$rootDir/node_modules/.bin/zklessc", '-s', "src/main/resources/web/${project.name}", '-o', "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(
"Manifest-Version": 1.0,
"Built-By": 'zkoss',
"Created-By": 'Gradle ' + project.getGradle().getGradleVersion(),
"Build-Jdk": JavaVersion.current()
)
}
}
// 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, source.jar & pom.xml into one bundle.jar
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)
}
}
task prepareZipSources() {
dependsOn 'jar'
dependsOn 'sourcesJar'
doLast {
// prepare lib
copy {
from "$buildDir/libs/${project.name}-${project.version}.jar"
into "$buildDir/zip/bin/dist/lib"
rename "${project.name}-${project.version}.jar", "${project.name}.jar"
}
// prepare src
copy {
from "$buildDir/libs/${project.name}-${project.version}-sources.jar"
into "$buildDir/zip/bin/dist/src"
rename "${project.name}-${project.version}-sources.jar", "${project.name}-sources.jar"
}
// prepare doc
copy {
from "$projectDir/zkdoc"
into "$buildDir/zip/bin/doc"
}
}
}
// build zip for release
task zip(type: Zip) {
dependsOn 'prepareZipSources'
archiveFileName = "${project.name}-${project.version}.zip"
destinationDirectory = file("$buildDir/zip")
from "$buildDir/zip/bin"
}
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"
}
}
}
// Delete codegen folder before clean
clean.doFirst {
delete "$projectDir/codegen/"
}
// change the version in gradle.properties
// 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",
)
}
}
}
}