forked from peterarsentev/job4j_devops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
204 lines (167 loc) · 6.24 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
plugins {
checkstyle
java
jacoco
id("org.springframework.boot") version "3.4.0"
id("io.spring.dependency-management") version "1.1.6"
id("com.github.spotbugs") version "6.0.26"
id("org.liquibase.gradle") version "3.0.1"
id("co.uzzu.dotenv.gradle") version "4.0.0"
}
group = "ru.job4j.devops"
version = "1.0.0"
tasks.jacocoTestCoverageVerification {
violationRules {
rule {
limit {
minimum = "0.5".toBigDecimal()
}
}
rule {
isEnabled = false
element = "CLASS"
includes = listOf("org.gradle.*")
limit {
counter = "LINE"
value = "TOTALCOUNT"
maximum = "0.3".toBigDecimal()
}
}
}
}
repositories {
mavenCentral()
}
dependencies {
compileOnly(libs.lombok)
annotationProcessor(libs.lombok)
implementation(libs.org.springframework.boot.spring.boot.starter.web)
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.liquibase:liquibase-core:4.30.0")
implementation("org.postgresql:postgresql:42.7.4")
implementation("org.springframework.kafka:spring-kafka")
testImplementation("org.awaitility:awaitility")
testImplementation("org.testcontainers:kafka:1.20.4")
testImplementation(libs.org.springframework.boot.spring.boot.starter.test)
testImplementation(libs.org.junit.jupiter.junit.jupiter)
testImplementation(libs.org.assertj.assertj.core)
testImplementation("org.testcontainers:postgresql:1.20.4")
testRuntimeOnly(libs.org.junit.platform.junit.platform.launcher)
liquibaseRuntime("org.liquibase:liquibase-core:4.30.0")
liquibaseRuntime("org.postgresql:postgresql:42.7.4")
liquibaseRuntime("javax.xml.bind:jaxb-api:2.3.1")
liquibaseRuntime("ch.qos.logback:logback-core:1.5.15")
liquibaseRuntime("ch.qos.logback:logback-classic:1.5.15")
liquibaseRuntime("info.picocli:picocli:4.6.1")
}
tasks.withType<Test> {
useJUnitPlatform()
}
tasks.register<Zip>("zipJavaDoc") {
group = "documentation" // Группа, в которой будет отображаться задача
description = "Packs the generated Javadoc into a zip archive"
dependsOn("javadoc") // Указываем, что задача зависит от выполнения javadoc
from("build/docs/javadoc") // Исходная папка для упаковки
archiveFileName.set("javadoc.zip") // Имя создаваемого архива
destinationDirectory.set(layout.buildDirectory.dir("archives")) // Директория, куда будет сохранен архив
}
tasks.spotbugsMain {
reports.create("html") {
required = true
outputLocation.set(layout.buildDirectory.file("reports/spotbugs/spotbugs.html"))
}
}
tasks.test {
finalizedBy(tasks.spotbugsMain)
}
tasks.register("checkJarSize") {
group = "verification"
description = "Checks the size of the generated JAR file."
dependsOn("jar") // Задача зависит от сборки JAR
doLast {
val jarFile = file("build/libs/${project.name}-${project.version}.jar") // Путь к JAR-файлу
if (jarFile.exists()) {
val sizeInMB = jarFile.length() / (1024 * 1024) // Размер в мегабайтах
if (sizeInMB > 20) {
println("WARNING: JAR file exceeds the size limit of 5 MB. Current size: ${sizeInMB} MB")
} else {
println("JAR file is within the acceptable size limit. Current size: ${sizeInMB} MB")
}
} else {
println("JAR file not found. Please make sure the build process completed successfully.")
}
}
}
tasks.register<Zip>("archiveResources") {
group = "custom optimization"
description = "Archives the resources folder into a ZIP file"
val inputDir = file("src/main/resources")
val outputDir = layout.buildDirectory.dir("archives")
inputs.dir(inputDir) // Входные данные для инкрементальной сборки
outputs.file(outputDir.map { it.file("resources.zip") }) // Выходной файл
from(inputDir)
destinationDirectory.set(outputDir)
archiveFileName.set("resources.zip")
doLast {
println("Resources archived successfully at ${outputDir.get().asFile.absolutePath}")
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.liquibase:liquibase-core:4.30.0")
}
}
liquibase {
activities.register("main") {
this.arguments = mapOf(
"logLevel" to "info",
"url" to env.DB_URL.value,
"username" to env.DB_USERNAME.value,
"password" to env.DB_PASSWORD.value,
"classpath" to "src/main/resources",
"changelogFile" to "db/changelog/db.changelog-master.xml"
)
}
runList = "main"
}
tasks.register("profile") {
doFirst {
println(env.DB_URL.value)
}
}
tasks.named<Test>("test") {
systemProperty("spring.datasource.url", env.DB_URL.value)
systemProperty("spring.datasource.username", env.DB_USERNAME.value)
systemProperty("spring.datasource.password", env.DB_PASSWORD.value)
}
val integrationTest by sourceSets.creating {
java {
srcDir("src/integrationTest/java")
}
resources {
srcDir("src/integrationTest/resources")
}
// Let the integrationTest classpath include the main and test outputs
compileClasspath += sourceSets["main"].output + sourceSets["test"].output
runtimeClasspath += sourceSets["main"].output + sourceSets["test"].output
}
val integrationTestImplementation by configurations.getting {
extendsFrom(configurations["testImplementation"])
}
val integrationTestRuntimeOnly by configurations.getting {
extendsFrom(configurations["testRuntimeOnly"])
}
tasks.register<Test>("integrationTest") {
description = "Runs the integration tests."
group = "verification"
testClassesDirs = integrationTest.output.classesDirs
classpath = integrationTest.runtimeClasspath
// Usually run after regular unit tests
shouldRunAfter(tasks.test)
}
tasks.check {
dependsOn("integrationTest")
}