-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
163 lines (146 loc) · 5.23 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
buildscript {
ext {
dependencyVersion = [
kotlin: '1.2.30',
junit : '5.1.0',
hamcrest: '1.3',
guava: '24.1-jre'
]
pluginVersion = [
junit : '1.1.0',
kotlin: dependencyVersion.kotlin,
dokka: '0.9.16-eap-1'
]
}
repositories {
mavenCentral()
jcenter()
maven { // TODO: Remove this repo once upgraded off eap to 0.9.16
url 'https://dl.bintray.com/kotlin/kotlin-eap/'
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${pluginVersion.kotlin}"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:${pluginVersion.dokka}"
classpath "org.junit.platform:junit-platform-gradle-plugin:${pluginVersion.junit}"
}
}
allprojects {
version = '0.0.1-SNAPSHOT'
group = 'tarro'
ext {
moduleName = "${group}.${project.name}"
}
}
def getGitHash = { ->
def sink = new ByteArrayOutputStream()
exec {
commandLine 'git', 'rev-parse', 'HEAD'
standardOutput = sink
}
return sink.toString().trim()
}
def mostRecentFileModifyTime = { -> // FIXME: Currently unused
return Files.walk(Paths.get("${projectDir}"))
.map { it.toFile().lastModified() }
.sorted(Comparator.comparingLong { it }.reversed())
.findFirst()
.map { Instant.ofEpochMilli(it).toString() }
.orElse("<UNKNOWN>")
}
def javaVersion = { ->
return 'Java ' + System.getProperty('java.version') + ' (' +
System.getProperty('java.vendor') + ')'
}
subprojects {
apply plugin: 'kotlin'
apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'org.junit.platform.gradle.plugin'
sourceCompatibility = 1.10
targetCompatibility = 1.10
dependencies {
testCompile "org.junit.jupiter:junit-jupiter-api:${dependencyVersion.junit}"
testCompile "org.junit.jupiter:junit-jupiter-params:${dependencyVersion.junit}"
testCompile "org.hamcrest:hamcrest-all:${dependencyVersion.hamcrest}"
testCompile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${dependencyVersion.kotlin}"
testCompile "com.google.guava:guava:${dependencyVersion.guava}"
testRuntime "org.junit.jupiter:junit-jupiter-engine:${dependencyVersion.junit}"
}
checkstyle {
configDir = rootProject.file('config/checkstyle/')
configFile = new File(configDir, 'checkstyle.xml')
configProperties = [
configDir: configDir
]
showViolations false
toolVersion = 8.7
}
compileJava {
// Needed to make the Gradle compile phase work with Java 9/Jigsaw.
// https://guides.gradle.org/building-java-9-modules
inputs.property("moduleName", moduleName)
options.compilerArgs << '-Xlint:all' << '-Werror'
doFirst {
options.compilerArgs << '--module-path' << classpath.asPath
classpath = files()
}
}
junitPlatformTest {
jvmArgs '-ea'
}
jar {
baseName = 'tarro-' + project.name.replace('.', '-')
manifest {
attributes(
'Implementation-Title': "${project.group}:${project.name}",
'Implementation-Version': project.version,
'Created-By': javaVersion(),
'Built-With': "gradle-${project.getGradle().getGradleVersion()}, groovy-${GroovySystem.getVersion()}",
'Built-By': System.getProperty('user.name'),
'Build-Commit': getGitHash(),
// FIXME: This Last-Modified-Time stamp causes the JAR to rebuild
// every time. Find a way to disable it except for release
// builds.
// 'Last-Modified-Time': mostRecentFileModifyTime()
)
}
from {
"${project.rootDir}/LICENSE"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = '1.8'
}
}
task unitTest {
// Run the tests, excluding tests tagged as slow. This '-T <tag>'
// command line argument replicates what the 'junitPlatform { }' closure
// does when you say 'filters { tags { excludes ... } }'. Since at the
// moment (v1.0.2 of the Gradle plugin) Jupiter doesn't provide a way to
// conditionally set the excludes based on the task you're trying to do,
// this is the workaround. So use `$ gradle unitTest` to run quick tests
// and `$ gradle test` to include the slow-running ones.
doLast {
junitPlatformTest {
jvmArgs '-ea'
args '-T slow'
}
}
}
unitTest.dependsOn testClasses
unitTest.finalizedBy junitPlatformTest
javadoc {
// Needed to make Gradle javadoc task work with Java 9 modules until
// Gradle introduces better handling for the module system.
// https://stackoverflow.com/a/48652316/1911388
inputs.property("moduleName", moduleName)
doFirst {
options.addStringOption('-module-path', classpath.asPath)
}
}
}
import java.nio.file.Files
import java.nio.file.Paths
import java.time.Instant