-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
134 lines (111 loc) · 3.33 KB
/
build.gradle
File metadata and controls
134 lines (111 loc) · 3.33 KB
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
buildscript {
// Lock buildscript dependencies.
configurations.classpath {
resolutionStrategy.activateDependencyLocking()
}
dependencies {
classpath 'com.google.guava:guava:26.0-jre'
}
}
plugins {
id 'com.diffplug.gradle.spotless' version '3.18.0' apply false
// gradlew <GradleTask> taskTree
id "com.dorongold.task-tree" version "1.4"
id 'jacoco'
}
dependencyLocking {
lockAllConfigurations()
}
subprojects {
repositories {
mavenCentral()
}
buildscript {
// Lock buildscript dependencies.
configurations.classpath {
resolutionStrategy.activateDependencyLocking()
}
}
// Lock application dependencies.
dependencyLocking {
lockAllConfigurations()
}
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'com.diffplug.gradle.spotless'
apply plugin: 'jacoco'
spotless {
java {
googleJavaFormat()
}
format 'misc', {
target '**/*.gradle', '**/*.md', '**/.gitignore', '**/*.sql'
targetExclude 'src/test/resources/**/*.sql'
trimTrailingWhitespace()
indentWithSpaces(2)
endWithNewline()
}
}
ext.getPropertyOrDefault = { name, defaultValue ->
if (project.hasProperty(name)) {
return project.findProperty(name)
}
return defaultValue
}
dependencies {
compile 'com.google.guava:guava:26.0-jre'
runtimeOnly 'org.postgresql:postgresql:42.2.5'
testCompile 'org.testcontainers:testcontainers:1.12.0'
testCompile 'org.testcontainers:postgresql:1.12.0'
testCompile 'com.google.truth.extensions:truth-java8-extension:0.45'
testCompile 'com.google.truth:truth:0.45'
testCompile 'junit:junit:4.13-beta-2'
}
test {
testLogging.showStandardStreams = true
finalizedBy jacocoTestReport
}
}
task checkSimultaneousChanges {
doLast {
def appChanges =
rootProject.ext.changedFileCount('subprojects/demo_app', false)
def schemaChanges =
rootProject.ext.changedFileCount('subprojects/demo_schema', false)
if (appChanges > 0 && schemaChanges > 0) {
throw new IllegalStateException(
'Simultaneous changes to both demo_schema and demo_app '
+ 'may not be submitted.')
}
}
}
// Root project does not have a build. Define one so that 'checkSimultaneousChanges'
// can be run as a task. If run in afterEvaluate block, an error would be attributed to
// project configuration error.
task build {
dependsOn subprojects.build
finalizedBy checkSimultaneousChanges
}
rootProject.ext {
// Executes an arbitrary shell command in bash and returns all output
// to stdout as a string. This method allows pipes in shell command.
execWithBash = { shellCommand, bashWorkingDir ->
return new ByteArrayOutputStream().withStream { os ->
exec {
workingDir bashWorkingDir
commandLine 'bash', '-c', "${shellCommand}"
standardOutput os
}
return os
}.toString()
}
// Counts the changed files under the given folder against origin/master.
changedFileCount = { folderName, stagedOnly ->
def shellCommand =
String.format('git diff --name-only %s origin/master %s | wc -l',
stagedOnly ? '--staged' : '',
folderName)
return Integer.valueOf(
rootProject.ext.execWithBash(shellCommand, rootDir).trim())
}
}