forked from kob-aha/maven-incremental-build-hello-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
95 lines (68 loc) · 2.71 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
description = 'hello-app'
// Variable that will contain the list of changed modules
ext.changedModulesNames = ''
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
// println "project ${innerProject} ownSrcDirs ${ownSrcDirs}"
// println "project ${innerProject} depSrcDirs ${dependentSrcDirs}"
inputs.files dependentSrcDirs
inputs.files ownSrcDirs
outputs.dir file("${innerProject.projectDir}/target")
doLast {
println "Module ${innerProject.name} had been changed. Adding to build list"
if (rootProject.ext.changedModulesNames) {
rootProject.ext.changedModulesNames += ",:${project.name}"
} else {
rootProject.ext.changedModulesNames += ":${project.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 buildChangedModules(type: Exec, description: 'Build changed modules using Maven') {
// Make sure that this task depends on checkModuleChanged in all projects
subprojects.each { subproject ->
dependsOn << ":${subproject.name}:checkModuleChanged"
}
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()
}