-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
250 lines (220 loc) · 9.44 KB
/
build.gradle
File metadata and controls
250 lines (220 loc) · 9.44 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
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import org.springframework.boot.gradle.tasks.run.BootRun
plugins {
id 'java'
id 'jvm-test-suite'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
id 'org.flywaydb.flyway' version '9.22.3'
id 'application'
}
group = 'com.recicar'
version = '0.0.1-SNAPSHOT'
java {
// Use Java 17 toolchain to match local environment and ensure tests compile
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
// Cucumber source set for BDD specs
sourceSets {
cucumber {
java {
srcDirs = ['src/cucumber/java']
}
resources {
srcDirs = ['src/cucumber/resources']
}
// Ensure Cucumber can see main and test dependencies
compileClasspath += sourceSets.main.output + configurations.testRuntimeClasspath
runtimeClasspath += output + compileClasspath
}
}
configurations {
// Ensure cucumber source set can use test and main deps
cucumberImplementation {
extendsFrom testImplementation
}
cucumberRuntimeOnly {
extendsFrom testRuntimeOnly
}
}
dependencies {
// Spring Boot Starters
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
// Database
implementation 'org.postgresql:postgresql'
implementation 'org.flywaydb:flyway-core'
// Redis for caching - temporarily disabled
// implementation 'org.springframework.boot:spring-boot-starter-data-redis'
// Rate Limiting - temporarily disabled due to dependency issues
// implementation 'io.github.bucket4j:bucket4j-core:8.7.0'
// Development tools
developmentOnly 'org.springframework.boot:spring-boot-devtools'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
// Annotation processors
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// Testing
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.testcontainers:junit-jupiter'
testImplementation 'org.testcontainers:postgresql'
testRuntimeOnly 'com.h2database:h2'
// Cucumber (BDD)
cucumberImplementation 'io.cucumber:cucumber-java:7.14.0'
cucumberImplementation 'io.cucumber:cucumber-spring:7.14.0'
// Optional: engine to allow running Cucumber via JUnit Platform if desired
testImplementation 'io.cucumber:cucumber-junit-platform-engine:7.14.0'
}
testing {
suites {
test {
useJUnitJupiter()
}
}
}
// Helper to load .env key/value pairs without external plugins
ext.loadDotEnv = {
def envMap = [:]
def envFile = file('.env')
if (envFile.exists()) {
envFile.eachLine { line ->
def trimmed = line.trim()
if (!trimmed || trimmed.startsWith('#')) return
def idx = trimmed.indexOf('=')
if (idx > 0) {
def key = trimmed.substring(0, idx).trim()
def value = trimmed.substring(idx + 1).trim()
envMap[key] = value
}
}
}
return envMap
}
// Si existe TEST_* en .env / entorno, los tests usan ese PostgreSQL (p. ej. misma URL que el servicio de test en Dokploy o CI).
tasks.named('test', Test) {
useJUnitPlatform {
// @Tag("integration") uses Testcontainers; run with: ./gradlew test -PincludeIntegration
if (!project.hasProperty('includeIntegration')) {
excludeTags 'integration'
}
}
def envs = loadDotEnv()
def testUrl = envs['TEST_DATABASE_URL'] ?: System.getenv('TEST_DATABASE_URL')
if (testUrl) {
// Integration tests against PostgreSQL: URL + driver must match (else H2 from yaml is paired with a jdbc:postgresql URL).
environment 'SPRING_DATASOURCE_URL', testUrl
environment 'SPRING_DATASOURCE_DRIVER_CLASS_NAME', 'org.postgresql.Driver'
environment 'SPRING_DATASOURCE_USERNAME', envs['TEST_DATABASE_USERNAME'] ?: System.getenv('TEST_DATABASE_USERNAME') ?: ''
environment 'SPRING_DATASOURCE_PASSWORD', envs['TEST_DATABASE_PASSWORD'] ?: System.getenv('TEST_DATABASE_PASSWORD') ?: ''
environment 'SPRING_FLYWAY_ENABLED', 'true'
environment 'SPRING_JPA_HIBERNATE_DDL_AUTO', 'validate'
}
}
flyway {
// Local dev: esquema "recicar" (evita permission denied en public en PostgreSQL 15+)
url = System.getenv('DATABASE_URL') ?: 'jdbc:postgresql://localhost:5432/marketplace_dev'
user = System.getenv('DATABASE_USERNAME') ?: 'marketplace_user'
password = System.getenv('DATABASE_PASSWORD') ?: 'marketplace_pass'
locations = ['classpath:db/migration']
schemas = ['recicar']
defaultSchema = 'recicar'
createSchemas = true
}
application {
mainClass = 'com.recicar.marketplace.MarketplaceApplication'
}
// Apply Cucumber task wiring and runners
apply from: 'gradle/cucumber.gradle'
// Convenience run tasks for each environment that source values from .env
tasks.register('runLocal', BootRun) {
group = 'application'
description = 'Run app with dev profile and local PostgreSQL'
dependsOn 'classes'
classpath = sourceSets.main.runtimeClasspath
systemProperty 'spring.profiles.active', 'dev'
// Local uses defaults in application.yml, no need to inject DB envs
mainClass.set(application.mainClass)
}
tasks.register('runTest', BootRun) {
group = 'application'
description = 'Run app with test profile (PostgreSQL; credenciales TEST_* en .env o entorno, p. ej. BD en Dokploy test)'
dependsOn 'classes'
classpath = sourceSets.main.runtimeClasspath
def envs = loadDotEnv()
systemProperty 'spring.profiles.active', 'test'
// Map TEST_ variables onto the generic names Spring expects
environment 'DATABASE_URL', envs['TEST_DATABASE_URL'] ?: System.getenv('TEST_DATABASE_URL')
environment 'DATABASE_USERNAME', envs['TEST_DATABASE_USERNAME'] ?: System.getenv('TEST_DATABASE_USERNAME')
environment 'DATABASE_PASSWORD', envs['TEST_DATABASE_PASSWORD'] ?: System.getenv('TEST_DATABASE_PASSWORD')
if (envs['JWT_SECRET']) environment 'JWT_SECRET', envs['JWT_SECRET']
mainClass.set(application.mainClass)
}
tasks.register('runProd', BootRun) {
group = 'application'
description = 'Run app with prod profile (PostgreSQL; credenciales PROD_* en .env o entorno)'
dependsOn 'classes'
classpath = sourceSets.main.runtimeClasspath
def envs = loadDotEnv()
systemProperty 'spring.profiles.active', 'prod'
// Map PROD_ variables onto the generic names Spring expects
environment 'DATABASE_URL', envs['PROD_DATABASE_URL'] ?: System.getenv('PROD_DATABASE_URL')
environment 'DATABASE_USERNAME', envs['PROD_DATABASE_USERNAME'] ?: System.getenv('PROD_DATABASE_USERNAME')
environment 'DATABASE_PASSWORD', envs['PROD_DATABASE_PASSWORD'] ?: System.getenv('PROD_DATABASE_PASSWORD')
if (envs['JWT_SECRET']) environment 'JWT_SECRET', envs['JWT_SECRET']
mainClass.set(application.mainClass)
}
// Also wire Flyway convenience tasks per environment
tasks.register('flywayMigrateDev') {
group = 'flyway'
description = 'Run Flyway migrate using local dev DB (from defaults)'
doFirst {
println 'Running Flyway migrate for DEV (local defaults)'
}
finalizedBy 'flywayMigrate'
}
tasks.register('flywayMigrateTest') {
group = 'flyway'
description = 'Run Flyway migrate against PostgreSQL de test (.env TEST_* o variables de entorno)'
doFirst {
def envs = loadDotEnv()
project.extensions.flyway.url = envs['TEST_DATABASE_URL'] ?: System.getenv('TEST_DATABASE_URL')
project.extensions.flyway.user = envs['TEST_DATABASE_USERNAME'] ?: System.getenv('TEST_DATABASE_USERNAME')
project.extensions.flyway.password = envs['TEST_DATABASE_PASSWORD'] ?: System.getenv('TEST_DATABASE_PASSWORD')
// Test/prod hosted: tablas en public (distinto del esquema recicar del dev local)
project.extensions.flyway.schemas = ['public']
project.extensions.flyway.defaultSchema = 'public'
project.extensions.flyway.createSchemas = false
}
finalizedBy 'flywayMigrate'
}
tasks.register('flywayMigrateProd') {
group = 'flyway'
description = 'Run Flyway migrate against PROD (.env PROD_* o variables de entorno)'
doFirst {
def envs = loadDotEnv()
project.extensions.flyway.url = envs['PROD_DATABASE_URL'] ?: System.getenv('PROD_DATABASE_URL')
project.extensions.flyway.user = envs['PROD_DATABASE_USERNAME'] ?: System.getenv('PROD_DATABASE_USERNAME')
project.extensions.flyway.password = envs['PROD_DATABASE_PASSWORD'] ?: System.getenv('PROD_DATABASE_PASSWORD')
project.extensions.flyway.schemas = ['public']
project.extensions.flyway.defaultSchema = 'public'
project.extensions.flyway.createSchemas = false
}
finalizedBy 'flywayMigrate'
}