forked from milos85vasic/Mail-Server-Factory
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
153 lines (130 loc) Β· 4.66 KB
/
build.gradle
File metadata and controls
153 lines (130 loc) Β· 4.66 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
plugins {
id 'org.jetbrains.kotlin.jvm' version '2.0.21' apply false
id 'org.sonarqube' version '4.4.1.3373'
}
ext {
kotlinVersion = "2.0.21" as Object
}
// Apply JaCoCo to all subprojects for test coverage
allprojects {
repositories {
google()
mavenCentral()
}
// Performance optimizations
tasks.withType(JavaCompile).configureEach {
options.compilerArgs.addAll([
'-XDcompilePolicy=simple', // Faster compilation
'-Xmaxerrs', '500', // Allow more errors before stopping
'-Xmaxwarns', '500' // Allow more warnings
])
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
kotlinOptions {
jvmTarget = '17'
freeCompilerArgs = [
'-Xjvm-default=all', // Better Java interop
'-Xinline-classes', // Performance optimization
'-opt-in=kotlin.RequiresOptIn' // Enable opt-in features
]
}
}
}
// SonarQube configuration - simplified for Factory module only
sonar {
properties {
property 'sonar.projectKey', 'mail-server-factory'
property 'sonar.projectName', 'Mail Server Factory'
property 'sonar.projectVersion', '1.0.0'
property 'sonar.sourceEncoding', 'UTF-8'
property 'sonar.language', 'kotlin'
// Skip automatic compilation
property 'sonar.gradle.skipCompile', 'true'
// Only analyze Factory module
property 'sonar.sources', 'Factory/src/main/kotlin'
property 'sonar.tests', 'Factory/src/test/kotlin'
// Kotlin specific settings
property 'sonar.kotlin.file.suffixes', '.kt'
// Coverage
property 'sonar.coverage.jacoco.xmlReportPaths', 'Factory/build/reports/jacoco/test/jacocoTestReport.xml'
// Quality Gate settings - require 100% success
property 'sonar.qualitygate.wait', 'true'
property 'sonar.qualitygate.timeout', '300'
// Local development - skip authentication for CI/testing
property 'sonar.login', 'admin'
property 'sonar.password', 'admin'
}
}
// Custom SonarQube quality check task
task sonarQualityCheck(type: Exec) {
group = 'verification'
description = 'Runs SonarQube analysis and ensures 100% quality gate success'
commandLine 'sh', '-c', '''
echo "π Running SonarQube Code Quality Analysis..."
# Check if containers are running
if ! docker ps | grep -q sonarqube; then
echo "β SonarQube container not running. Please start containers with: docker compose up -d"
exit 1
fi
if ! docker ps | grep -q postgresql; then
echo "β PostgreSQL container not running. Please start containers with: docker compose up -d"
exit 1
fi
# Run the analysis script
./sonar-analysis.sh
'''
}
subprojects {
apply plugin: 'jacoco'
jacoco {
toolVersion = "0.8.12"
}
tasks.withType(Test).configureEach {
jacoco {
enabled = true
}
finalizedBy jacocoTestReport
}
afterEvaluate {
if (tasks.findByName('test')) {
tasks.jacocoTestReport {
dependsOn test
reports {
xml.required = true
html.required = true
csv.required = true
}
}
}
}
}
// Comprehensive test task that includes SonarQube analysis
task allTests {
group = 'verification'
description = 'Runs all tests including unit tests, coverage, and SonarQube quality analysis'
// Ensure SonarQube containers are running first
doFirst {
exec {
commandLine 'sh', '-c', '''
echo "π Checking SonarQube containers..."
if ! docker ps | grep -q sonarqube; then
echo "β SonarQube container not running. Starting containers..."
docker compose up -d
echo "β³ Waiting for SonarQube to be ready..."
for i in {1..30}; do
if curl -s http://localhost:9000/api/system/status | grep -q '"status":"UP"'; then
echo "β
SonarQube is ready"
break
fi
echo "Waiting... ($i/30)"
sleep 10
done
else
echo "β
SonarQube containers are running"
fi
'''
}
}
// Make allTests depend on the quality check
dependsOn sonarQualityCheck
}