forked from Baeldung/kotlin-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
98 lines (83 loc) · 2.61 KB
/
build.gradle.kts
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
import java.io.ByteArrayOutputStream
import java.io.FileOutputStream
import java.io.OutputStream
plugins {
`java-library`
id("org.flywaydb.flyway") version "8.0.2"
}
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven {
url = uri("https://maven.springframework.org/release")
}
}
sourceSets {
create("integrationTest") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
}
val integrationTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations.implementation.get())
extendsFrom(configurations.testImplementation.get())
}
val integrationTestRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.implementation.get())
extendsFrom(configurations.testRuntimeOnly.get())
}
val integrationTest = task<Test>("integrationTest") {
description = "Task to run integration tests"
group = "verification"
testClassesDirs = sourceSets["integrationTest"].output.classesDirs
classpath = sourceSets["integrationTest"].runtimeClasspath
shouldRunAfter("test")
}
tasks.check { dependsOn(integrationTest) }
dependencies {
api("com.google.inject:guice:5.0.1")
implementation("com.google.guava:guava:31.0-jre")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
testImplementation("org.mockito:mockito-core:4.0.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}
tasks.register("helloUserCmd") {
val user: String? = System.getenv("USER")
project.exec {
commandLine("echo", "Hello,", "$user!")
}
}
tasks.register("helloUserInVarCmd") {
val outputStream = ByteArrayOutputStream()
val user: String? = System.getenv("USER")
project.exec {
standardOutput = outputStream
commandLine("echo", "Hello,", "$user!")
}
val output = outputStream.toString().trim()
println("Command output: $output")
}
tasks.register("tmpFilesCmd") {
val outputFile = File("/tmp/output.txt")
val outputStream: OutputStream = FileOutputStream(outputFile)
project.exec {
standardOutput = outputStream
workingDir = project.file("/tmp")
commandLine("ls", workingDir)
}
}
tasks.register("alwaysFailCmd") {
val result = project.exec {
commandLine("ls", "invalid_path")
isIgnoreExitValue = true
}
if (result.exitValue == 0) {
println("Command executed successfully.")
} else {
println("Command execution failed.")
println("Command status: $result")
}
}