-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
114 lines (83 loc) · 3.5 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
description = 'hello-app'
// Variable that will contain the list of changed modules
ext.changedModulesNames = ''
ext.changedModules = [] as Set
ext.outputFileName = 'build-success.txt'
allprojects { innerProject ->
group = 'edu.ka.hello.increment'
version = '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.6
targetCompatibility = 1.6
afterEvaluate {
task checkModuleChanged {
description 'Checks whether a certain module had been changed in order to be build using Maven'
// Configures project and dependent source directories as inputs
def projCompileDeps = innerProject.configurations.compile.getAllDependencies().withType(ProjectDependency)
def projRuntimeDeps = innerProject.configurations.runtime.getAllDependencies().withType(ProjectDependency)
def dependedUponProjects = (projCompileDeps + projRuntimeDeps)*.dependencyProject
def dependentSrcDirs = dependedUponProjects*.sourceSets*.main*.allSource*.srcDirs
def ownSrcDirs = innerProject.sourceSets.main.allSource.srcDirs
def ownTestDirs = innerProject.sourceSets.test.allSource.srcDirs
inputs.files files(dependentSrcDirs, ownSrcDirs, ownTestDirs, "${innerProject.projectDir}/pom.xml")
outputs.upToDateWhen {
new File("${innerProject.projectDir}/target/${rootProject.ext.outputFileName}").exists()
}
doLast {
println "Module ${innerProject.name} had been changed. Adding to build list"
rootProject.ext.changedModules << innerProject
if (rootProject.ext.changedModulesNames) {
rootProject.ext.changedModulesNames += ",:${innerProject.name}"
} else {
rootProject.ext.changedModulesNames += ":${innerProject.name}"
}
}
}
}
}
project(":hello-webapp") {
description = 'Hello world web application'
apply plugin: 'war'
apply plugin: 'jetty'
dependencies {
runtime project(':hello-impl')
}
}
project(":hello-impl") {
description = 'Hello world implementation'
dependencies {
compile project(':hello-api')
}
}
task cleanChangedModules(description: 'Deletes build success dummy file from changed modules', dependsOn: ":checkModuleChanged") {
// Make sure that this task depends on checkModuleChanged in all projects
subprojects.each { subproject ->
dependsOn << ":${subproject.name}:checkModuleChanged"
}
onlyIf {
project.ext.changedModulesNames
}
doFirst {
project.ext.changedModules.each { changedModule ->
new File("${changedModule.projectDir}/target/${rootProject.ext.outputFileName}").delete()
}
}
}
// This task dependsOn cleanChangedModules in order to make sure skipped modules are rebuild in case
// Maven execution fails in the middle
task buildChangedModules(type: Exec, description: 'Build changed modules using Maven', dependsOn: cleanChangedModules) {
onlyIf {
project.ext.changedModulesNames
}
doFirst {
commandLine 'mvn', 'clean', 'install', '-pl', "${project.ext.changedModulesNames}"
logger.info "Changed modules are: ${project.ext.changedModulesNames}"
logger.info "Executed command: ${commandLine}"
}
}
task createGradleWrapper(type: Wrapper) {
gradleVersion = '1.4'
}
repositories {
mavenCentral()
}