forked from gradle/gradle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
541 lines (470 loc) · 17.8 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
/*
* Copyright 2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.text.SimpleDateFormat
import java.util.jar.Attributes
import org.gradle.api.artifacts.repositories.WebdavResolver
import org.gradle.api.internal.artifacts.dependencies.DefaultSelfResolvingDependency
import org.gradle.build.samples.WrapperProjectCreator
import java.util.regex.Pattern
/**
* For building Gradle you usually don't need to specify any properties. Only certain functionality of the Gradle requires
* setting certain properties. Those properties can be set in the gradle.properties file in the the gradle user home. The
* following properties can be set:
*
* Uploading distributions to Gradle's release and snapshot repository at codehaus: codehausUserName, codehausUserPassword
* Uploading the userguide and the javadoc to Gradle's website: websiteFtpUserName, websiteFtpUserPassword
* Using the build to create a new distribution and install it on the local machine: gradle_installPath
*/
version = new Version(project)
defaultTasks 'assemble'
apply plugin: 'java-base'
startScriptsDir = new File("$buildDir/startScripts")
archivesBaseName = 'gradle'
libraries = [
ant: 'org.apache.ant:ant:1.8.1@jar',
ant_junit: 'org.apache.ant:ant-junit:1.8.1@jar',
ant_launcher: 'org.apache.ant:ant-launcher:1.8.1@jar',
ant_nodeps: 'org.apache.ant:ant-nodeps:1.8.1@jar',
ant_antlr: 'org.apache.ant:ant-antlr:1.8.1@jar',
antlr: 'antlr:antlr:2.7.7@jar',
asm_all: 'asm:asm-all:3.2@jar',
commons_cli: 'commons-cli:commons-cli:1.2@jar',
commons_io: 'commons-io:commons-io:1.4@jar',
commons_lang: 'commons-lang:commons-lang:2.5@jar',
dom4j: 'dom4j:dom4j:1.6.1@jar',
google_collections: 'com.google.collections:google-collections:1.0@jar',
groovy: 'org.codehaus.groovy:groovy-all:1.7.5@jar',
ivy: 'org.apache.ivy:ivy:2.2.0@jar',
jaxen: 'jaxen:jaxen:1.1@jar',
slf4j_api: 'org.slf4j:slf4j-api:1.6.1@jar',
jcl_to_slf4j: 'org.slf4j:jcl-over-slf4j:1.6.1@jar',
jul_to_slf4j: 'org.slf4j:jul-to-slf4j:1.6.1@jar',
log4j_to_slf4j: 'org.slf4j:log4j-over-slf4j:1.6.1@jar',
logback_classic: 'ch.qos.logback:logback-classic:0.9.24@jar',
logback_core: 'ch.qos.logback:logback-core:0.9.24@jar',
junit: 'junit:junit:4.8.1',
xmlunit: 'xmlunit:xmlunit:1.3',
]
libraries.spock = ['org.spockframework:spock-core:0.4-groovy-1.7@jar', libraries.groovy, 'cglib:cglib-nodep:2.2', 'org.objenesis:objenesis:1.2']
libraries.groovy_depends = [libraries.groovy, libraries.commons_cli]
libraries.jetty_depends = ["org.mortbay.jetty:jetty:6.1.25@jar", "org.mortbay.jetty:jetty-util:6.1.25@jar",
"org.mortbay.jetty:servlet-api:2.5-20081211@jar"]
allprojects {
group = 'org.gradle'
plugins.withType(JavaPlugin).whenPluginAdded {
sourceCompatibility = 1.5
targetCompatibility = 1.5
}
repositories {
mavenRepo(urls: 'http://gradle.artifactoryonline.com/gradle/libs')
}
version = this.version
}
def FIRST_LEVEL_JMOCK = ['org.hamcrest:hamcrest-core:1.1@jar', 'org.hamcrest:hamcrest-library:1.1@jar', 'org.jmock:jmock-junit4:2.5.1@jar']
configure(groovyProjects()) {
apply plugin: 'groovy'
apply plugin: 'eclipse'
archivesBaseName = "gradle-${name.replaceAll("\\p{Upper}") { "-${it.toLowerCase()}" } }"
dependencies {
testCompile libraries.junit, FIRST_LEVEL_JMOCK, libraries.spock
testCompile module("org.jmock:jmock:2.5.1") {
dependencies('org.jmock:jmock-legacy:2.5.1@jar', 'org.objenesis:objenesis:1.0', 'cglib:cglib-nodep:2.1_3')
dependencies(FIRST_LEVEL_JMOCK as Object[])
}
// todo - these should not be here
testCompile 'org.jmock:jmock-legacy:2.5.1@jar', 'org.objenesis:objenesis:1.0', 'cglib:cglib-nodep:2.1_3'
}
test {
maxParallelForks = guessMaxForks()
}
tasks.withType(Jar).each { jar ->
jar.manifest.mainAttributes([
(Attributes.Name.IMPLEMENTATION_TITLE.toString()): 'Gradle',
(Attributes.Name.IMPLEMENTATION_VERSION.toString()): version,
])
}
}
allprojects {
apply plugin: 'code-quality'
checkstyleConfigDir = "$rootDir/config/checkstyle"
checkstyleConfigFileName = new File(checkstyleConfigDir, "checkstyle.xml")
codeNarcConfigFileName = "$rootDir/config/codenarc.xml"
checkstyleProperties.checkstyleConfigDir = checkstyleConfigDir
}
configure(groovyProjects()) {
sourceSets.allObjects { sourceSet ->
task "${sourceSet.getTaskName('checkstyle', 'groovy')}"(type: Checkstyle) {
configFile = new File(checkstyleConfigDir, "checkstyle-groovy.xml")
source sourceSet.allGroovy
classpath = sourceSet.compileClasspath
resultFile = new File(checkstyleResultsDir, "${sourceSet.name}-groovy.xml")
}
}
}
allprojects {
apply plugin: 'idea'
apply plugin: 'eclipse'
def config = configurations.findByName('testRuntime')
if (!config) {
return
}
ideDir = file('ide')
task ide(type: Sync) {
into "$ideDir/lib"
from { config.copyRecursive {dep -> !(dep instanceof ProjectDependency)}.files }
}
ideaModule {
gradleCacheVariable = 'GRADLE_CACHE'
outputDir = "$rootProject.projectDir/intellij/out" as File
testOutputDir = "$rootProject.projectDir/intellij/testOut" as File
}
eclipseClasspath {
variables = [:]
}
}
ideaModule {
excludeDirs += file('intTestHomeDir')
excludeDirs += file('buildSrc/build')
excludeDirs += file('buildSrc/.gradle')
excludeDirs += file('performanceTest/.gradle')
excludeDirs += file('performanceTest/build')
excludeDirs += file('website/.gradle')
excludeDirs += file('website/build')
}
ideaProject {
wildcards += ['?*.gradle']
javaVersion = '1.6'
withXml { node ->
// Use git
def vcsConfig = node.component.find { it.'@name' == 'VcsDirectoryMappings' }
vcsConfig.mapping[0].'@vcs' = 'Git'
// Set gradle home
def gradleSettings = node.appendNode('component', [name: 'GradleSettings'])
gradleSettings.appendNode('option', [name: 'SDK_HOME', value: gradle.gradleHomeDir.absolutePath])
}
whenConfigured { project ->
project.jdk.languageLevel = 'JDK_1_5'
}
}
// Exclude resource directories from compilation and add them back in as classpath resources
ideaProject {
withXml { node ->
def compilerConfig = node.component.find { it.'@name' == 'CompilerConfiguration' }
def exclude = compilerConfig.appendNode('excludeFromCompile')
Collection resourceDirs = groovyProjects().collect { project -> project.sourceSets*.resources*.srcDirs }.flatten()
resourceDirs.each {
exclude.appendNode('directory', [url: "file://\$PROJECT_DIR\$/${rootProject.relativePath(it)}", includeSubdirectories: true])
}
}
}
configure(groovyProjects()) {
ideaModule {
scopes.RUNTIME.plus.add(configurations.detachedConfiguration(new DefaultSelfResolvingDependency(files { sourceSets.main.resources.srcDirs })))
scopes.TEST.plus.add(configurations.detachedConfiguration(new DefaultSelfResolvingDependency(files { sourceSets*.resources*.srcDirs })))
}
}
configurations {
dists
runtime {
visible = false
}
plugins {
visible = false
}
testRuntime {
extendsFrom runtime
extendsFrom plugins
}
}
dependencies {
runtime runtimeProjects()
plugins pluginProjects()
}
evaluationDependsOn(':docs')
evaluationDependsOn(':core')
clean.dependsOn subprojects.collect { "$it.path:clean" }
task check(overwrite: true, dependsOn: groovyProjects()*.check)
check.dependsOn ':docs:checkstyleApi'
task test(overwrite: true, dependsOn: groovyProjects()*.test)
zipRootFolder = "$archivesBaseName-${-> version}"
binDistImage = copySpec {
from 'src/toplevel'
from project(':docs').distDocs.destFile
into('bin') {
from startScriptsDir
fileMode = 0755
}
into('lib') {
from configurations.runtime
into('plugins') {
from configurations.plugins - configurations.runtime
}
}
}
allDistImage = copySpec {
with binDistImage
into('src') {
from groovyProjects().collect {project -> project.sourceSets.main.allSource }
}
into('docs') {
from project(':docs').docsDir
}
into('samples') {
from project(':docs').samplesDir
}
}
task allZip(type: Zip, dependsOn: ['launcher:startScripts', 'docs:docs', 'docs:samples']) {
classifier = 'all'
into(zipRootFolder) {
with allDistImage
}
}
task binZip(type: Zip, dependsOn: ['launcher:startScripts', 'docs:distDocs']) {
classifier = 'bin'
into(zipRootFolder) {
with binDistImage
}
}
task srcZip(type: Zip) {
classifier = 'src'
into(zipRootFolder) {
from('gradlew') {
fileMode = 0755
}
from(projectDir) {
def spec = delegate
['buildSrc', 'subprojects/*'].each {
spec.include "$it/*.gradle"
spec.include "$it/src/"
}
include 'config/'
include 'gradle/'
include 'src/'
include '*.gradle'
include 'gradle.properties'
include 'wrapper/'
include 'gradlew.bat'
}
}
}
artifacts {
tasks.withType(Zip).each {
dists it
}
}
task intTestImage(type: Sync) {
dependsOn allZip.taskDependencies
with allDistImage
integTestGradleHome = file("$buildDir/integ test")
into integTestGradleHome
doLast { task ->
ant.chmod(dir: "$integTestGradleHome/bin", perm: "ugo+rx", includes: "**/*")
WrapperProjectCreator.createProject(new File(integTestGradleHome, 'samples'), binZip.archivePath.parentFile, version.toString())
}
}
task integTest(type: Test, dependsOn: [intTestImage, binZip, allZip, srcZip, ':docs:userguideDocbook']) {
integTestUserDir = file('intTestHomeDir')
systemProperties['integTest.userGuideInfoDir'] = project(':docs').docbookSrc
systemProperties['integTest.userGuideOutputDir'] = new File(project(':docs').samplesSrcDir, "userguideOutput").absolutePath
systemProperties['integTest.gradleUserHomeDir'] = integTestUserDir.absolutePath
include 'org/gradle/integtests/**/*IntegrationTest.*'
forkEvery = 15
maxParallelForks = guessMaxForks()
testClassesDir = project(':core').sourceSets.integTest.classesDir
classpath = project(':core').sourceSets.integTest.runtimeClasspath + configurations.testRuntime
testResultsDir = file('build/test-results')
testReportDir = file('build/reports/tests')
testSrcDirs = []
doFirst {
if (isDevBuild()) {
exclude 'org/gradle/integtests/DistributionIntegrationTest.*'
}
systemProperties['integTest.gradleHomeDir'] = intTestImage.integTestGradleHome.absolutePath
def forkArgs
if (noForkIntegTests()) {
systemProperties['org.gradle.integtest.fork'] = "false"
jvmArgs '-Xmx512m', '-XX:MaxPermSize=256m', '-XX:+HeapDumpOnOutOfMemoryError'
} else {
jvmArgs '-Xmx512m', '-XX:+HeapDumpOnOutOfMemoryError'
}
}
}
boolean noForkIntegTests() {
if (project.hasProperty('forkIntegTests')) {
return !Boolean.valueOf(forkIntegTests)
}
return isDevBuild() && !OperatingSystem.current().isWindows()
}
private def isDevBuild() {
gradle.taskGraph.hasTask(':developerBuild')
}
def guessMaxForks() {
int processors = Runtime.runtime.availableProcessors()
return Math.max(2, (int) (processors / 2))
}
task testedDists(dependsOn: [assemble, check, integTest, 'openApi:integTest', ':ui:integTest'])
task nightlyBuild(dependsOn: [clean, testedDists, ':docs:uploadDocs'])
task install(type: Install, description: 'Installs the minimal distribution into directory $gradle_installPath') {
dependsOn binZip.taskDependencies
with binDistImage
installDirProperyName = 'gradle_installPath'
}
task installAll(type: Install, description: 'Installs the full distribution into directory $gradle_installPath') {
dependsOn allZip.taskDependencies
with allDistImage
installDirProperyName = 'gradle_installPath'
}
uploadDists {
dependsOn testedDists
uploadDescriptor = false
doFirst {
it.repositories.add(new WebdavResolver()) {
name = 'gradleReleases'
user = codehausUserName
userPassword = codehausUserPassword
addArtifactPattern("${version.distributionUrl}/[artifact]-[revision](-[classifier]).[ext]" as String)
}
}
}
gradle.taskGraph.whenReady {graph ->
if (graph.hasTask(uploadDists)) {
// check properties defined and fail early
codehausUserName
codehausUserPassword
}
}
task developerBuild(dependsOn: [clean, testedDists])
task ciBuild(dependsOn: [clean, testedDists])
gradle.taskGraph.whenReady {graph ->
if (graph.hasTask(ciBuild)) {
subprojects { reportsDirName = "$rootProject.reportsDir/${path.replaceFirst(':', '').replaceAll(':', '.')}" }
}
}
task release(dependsOn: [uploadDists, ':docs:uploadDocs']) << {
// Update the version properties in gradle.properties
// Properties props = new Properties()
// File propsFile = file('gradle.properties')
// propsFile.withReader { props.load(it) }
// props.previousVersion = props.nextVersion
// def nextVersion = props.nextVersion.split('\\.')
// nextVersion[1] = (nextVersion[1] as Integer) +1
// props.nextVersion = nextVersion.join('.')
// propsFile.withWriter { props.store(it, 'properties') }
// todo rewrite release functionality for Git. Until then we have to do tagging and branching manually.
}
task wrapper(type: Wrapper, dependsOn: binZip)
wrapper.doFirst {task ->
task.configure {
gradleVersion = version
jarPath = 'wrapper'
}
}
task rebuildWrapper(dependsOn: [clean, wrapper])
def groovyProjects() {
subprojects.findAll { project -> project.name != 'docs' }
}
def runtimeProjects() {
groovyProjects() - pluginProjects()
}
def pluginProjects() {
['plugins', 'codeQuality', 'jetty', 'antlr', 'wrapper', 'osgi', 'maven', 'eclipse', 'idea', 'announce', 'scala'].collect {
project(it)
}
}
class Version {
String versionNumber
Date buildTime
Boolean release = null
def Version(project) {
this.versionNumber = project.nextVersion
File timestampFile = new File(project.buildDir, 'timestamp.txt')
if (!timestampFile.isFile()) {
timestampFile.parentFile.mkdirs()
timestampFile.createNewFile()
} else {
boolean uptodate = true
def modified = timestampFile.lastModified()
project.project(':core').fileTree('src/main').visit {fte ->
if (fte.file.isFile() && fte.lastModified > modified) {
uptodate = false
fte.stopVisiting()
}
}
if (!uptodate) {
timestampFile.setLastModified(new Date().time)
}
}
buildTime = new Date(timestampFile.lastModified())
project.gradle.taskGraph.whenReady {graph ->
if (!graph.hasTask(':release')) {
this.versionNumber += "-" + getTimestamp()
release = false
} else {
release = true
}
}
}
String toString() {
versionNumber
}
String getTimestamp() {
new SimpleDateFormat('yyyyMMddHHmmssZ').format(buildTime)
}
boolean isRelease() {
if (release == null) {
throw new GradleException("Can't determine whether this is a release build before the task graph is populated")
}
return release
}
String getDistributionUrl() {
if (release) {
'https://dav.codehaus.org/dist/gradle'
} else {
'https://dav.codehaus.org/snapshots.dist/gradle'
}
}
}
class Install extends Sync {
String installDirProperyName
File installDir
def Install() {
addPropertyCheck()
doLast {
ant.chmod(file: "$installDir/bin/gradle", perm: 'ugo+x')
}
}
private void addPropertyCheck() {
project.gradle.taskGraph.whenReady {graph ->
if (graph.hasTask(path)) {
// Do this early to ensure that the properties we need have been set, and fail early
if (!project.hasProperty(installDirProperyName)) {
throw new RuntimeException("You can't install without setting the $installDirProperyName property.")
}
installDir = project.file(this.project."$installDirProperyName")
if (installDir.file) {
throw new RuntimeException("Install directory $installDir does not look like a Gradle installation. Cannot delete it to install.")
}
if (installDir.directory) {
File libDir = new File(installDir, "lib")
if (!libDir.directory || !libDir.list().findAll { it.matches('gradle.*\\.jar')}) {
throw new RuntimeException("Install directory $installDir does not look like a Gradle installation. Cannot delete it to install.")
}
}
into installDir
}
}
}
}