-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
193 lines (169 loc) · 7.1 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
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
import org.springframework.boot.gradle.tasks.run.BootRun
// The Flyway plugin requires the PostgreSQL JDBC driver to be present in the buildscript classpath
// so that it can be used to connect to the database and execute the migrations.
buildscript {
dependencies {
classpath('org.postgresql:postgresql:42.7.5')
classpath('org.flywaydb:flyway-database-postgresql:11.8.0')
}
}
plugins {
id 'org.springframework.boot'
id 'io.freefair.lombok'
id 'org.springdoc.openapi-gradle-plugin' version '1.9.0'
id 'org.openapi.generator' version '7.12.0'
id 'org.flywaydb.flyway' version '11.8.0'
}
// Detect if the generateOpenApiDocs task is being executed
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.hasTask(':application-server:generateOpenApiDocs') || taskGraph.hasTask(':application-server:bootRunOpenApi')) {
println "OpenAPI task detected. Adding H2 dependency."
// Add the H2 dependency dynamically
dependencies {
runtimeOnly 'com.h2database:h2'
}
}
}
configurations {
// Configuration that tracks the agents added to the JVM at run-time
runtimeAgent1
runtimeAgent2
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-aop'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.security:spring-security-oauth2-jose'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.6'
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
implementation 'io.nats:jnats:2.21.1'
implementation 'org.kohsuke:github-api:1.327'
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
implementation 'javax.annotation:javax.annotation-api:1.3.2'
implementation 'org.flywaydb:flyway-core:11.8.0'
implementation 'org.flywaydb:flyway-database-postgresql:11.8.0'
implementation 'io.jsonwebtoken:jjwt-api:0.12.6'
implementation 'io.sentry:sentry-spring-boot-starter-jakarta:8.10.0'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.6'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.6'
runtimeOnly 'org.postgresql:postgresql'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'io.zonky.test:embedded-database-spring-test:2.6.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
runtimeAgent1 "org.springframework:spring-instrument:6.2.6"
runtimeAgent2 "org.aspectj:aspectjweaver:1.9.24"
}
springBoot {
mainClass = "de.tum.cit.aet.helios.HeliosApplication"
}
// Custom bootRun task to force the user to specify an active profile
tasks.named("bootRun") {
doFirst {
def activeProfile = System.getProperty("spring.profiles.active")
?: project.findProperty("spring.profiles.active")
?: System.getenv("SPRING_PROFILES_ACTIVE")
if (!activeProfile) {
throw new GradleException("""
Error: 'spring.profiles.active' is not set.
Please specify an active profile using one of the following methods:
- Use a predefined task like 'bootRunDev'.
- Set the 'SPRING_PROFILES_ACTIVE' environment variable.
- Use the '-Dspring.profiles.active=<profile>' JVM argument.
Available profiles: dev, openapi (Don't use this profile directly).
Examples:
1. Using predefined task:
./gradlew bootRunDev
2. Setting environment variable:
export SPRING_PROFILES_ACTIVE=dev
./gradlew bootRun
3. Passing JVM argument:
./gradlew -Dspring.profiles.active=dev bootRun
4. Using project property:
./gradlew bootRun -Pspring.profiles.active=dev
"""
)
} else {
println "Running with profile: ${activeProfile}"
systemProperty "spring.profiles.active", activeProfile
}
}
}
tasks.register("bootRunDev", BootRun) {
jvmArgs = ["-javaagent:${configurations.runtimeAgent1.asPath}", "-javaagent:${configurations.runtimeAgent2.asPath}"]
group = "application"
description = "Runs the Spring Boot application with the dev profile"
// Set the active profile to 'dev'
systemProperty "spring.profiles.active", "dev"
classpath = sourceSets.main.runtimeClasspath
mainClass.set("de.tum.cit.aet.helios.HeliosApplication")
}
tasks.named("test") {
group = "application"
description = "Runs the Spring Boot application with the test profile"
// Set the active profile to 'test'
systemProperty "spring.profiles.active", "test"
finalizedBy "jacocoTestReport"
}
jacocoTestReport {
dependsOn test // tests are required to run before generating the report
reports {
xml.required = true
csv.required = false
}
}
tasks.register("bootRunOpenApi", BootRun) {
group = "application"
description = "Runs the Spring Boot application with the openapi profile"
systemProperty "spring.profiles.active", "openapi"
classpath = sourceSets.main.runtimeClasspath
mainClass.set("de.tum.cit.aet.helios.HeliosApplication")
}
tasks.register("makemigration", BootRun) {
group = "application"
description = "Proposes a new Flyway migration script"
systemProperty "spring.profiles.active", "migration"
classpath = sourceSets.main.runtimeClasspath
mainClass.set("de.tum.cit.aet.helios.HeliosApplication")
}
openApi {
apiDocsUrl = 'http://localhost:8080/v3/api-docs.yaml'
outputDir = file('.')
outputFileName = 'openapi.yaml'
// Set the active profile to 'openapi'
customBootRun {
args.set(["--spring.profiles.active=openapi", "-javaagent:${configurations.runtimeAgent1.asPath}", "-javaagent:${configurations.runtimeAgent2.asPath}"])
jvmArgs.set(["-javaagent:${configurations.runtimeAgent1.asPath}", "-javaagent:${configurations.runtimeAgent2.asPath}"])
}
waitTimeInSeconds.set(60)
}
tasks.named('test') {
useJUnitPlatform()
}
// Load environment variables from the .env file
// into the project properties so that they can be used
def envFile = file('.env')
if (envFile.exists()) {
envFile.readLines().each { line ->
def (key, value) = line.tokenize('=')
if (key && value) {
// Replace the double quotes around the value with an empty string
project.ext.set(key, value.trim().replaceAll('^"(.*)"$', '$1'))
}
}
}
flyway {
url = project.hasProperty('DATASOURCE_URL')
? project.DATASOURCE_URL
: System.getenv('DATASOURCE_URL')
user = project.hasProperty('DATASOURCE_USERNAME')
? project.DATASOURCE_USERNAME
: System.getenv('DATASOURCE_USERNAME')
password = project.hasProperty('DATASOURCE_PASSWORD')
? project.DATASOURCE_PASSWORD
: System.getenv('DATASOURCE_PASSWORD')
cleanDisabled = false
}