-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
89 lines (79 loc) · 3.03 KB
/
Copy pathbuild.gradle
File metadata and controls
89 lines (79 loc) · 3.03 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
plugins {
id 'java'
}
group = 'org.alxkm'
version = '1.0.0'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
repositories {
mavenCentral()
}
dependencies {
testImplementation platform('org.junit:junit-bom:6.1.3')
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
// The quiz is one dependency-free file, so Gradle is a convenience here rather than a requirement:
//
// ./gradlew quiz # this task
// java src/main/java/org/alxkm/interview/Quiz.java # same thing, no build
//
// --console=plain matters. Without it Gradle repaints its progress bar over the questions.
// A runnable jar that carries the questions with it, for `java -jar` and JBang. The release workflow
// attaches it to each GitHub release under this exact name, which the JBang catalog points at.
tasks.named('jar') {
archiveFileName = 'java-concurrency-interview.jar'
manifest {
attributes 'Main-Class': 'org.alxkm.interview.Quiz'
}
from('questions') {
into 'questions'
}
}
tasks.register('quiz', JavaExec) {
group = 'application'
description = 'Runs the interactive quiz. Use: ./gradlew quiz --console=plain -q'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'org.alxkm.interview.Quiz'
workingDir = projectDir
standardInput = System.in
args = (project.findProperty('args') ?: '').toString().split(' ').findAll { it }
}
// The README's question catalogue is generated from questions/*.md, so the quiz and the README can
// never drift apart. Everything outside the BEGIN/END markers is hand-written and left alone.
tasks.register('readme', JavaExec) {
group = 'documentation'
description = 'Regenerates the question catalogue inside README.md from questions/*.md'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'org.alxkm.interview.Quiz'
workingDir = projectDir
args = ['--export-readme']
}
tasks.register('stats', JavaExec) {
group = 'documentation'
description = 'Prints how many questions there are, by topic and by level.'
classpath = sourceSets.main.runtimeClasspath
mainClass = 'org.alxkm.interview.Quiz'
workingDir = projectDir
args = ['--stats']
}
tasks.named('test') {
useJUnitPlatform()
testLogging {
events 'passed', 'skipped', 'failed'
}
// The tests read questions/ and README.md from disk rather than from the classpath, so Gradle
// cannot see that a new question invalidates them. Without these, editing a question and running
// ./gradlew test reports success from a cached run that never looked at the new file.
inputs.dir('questions')
.withPropertyName('questions')
.withPathSensitivity(PathSensitivity.RELATIVE)
inputs.file('README.md')
.withPropertyName('readme')
.withPathSensitivity(PathSensitivity.RELATIVE)
}