-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle
More file actions
175 lines (150 loc) · 5.98 KB
/
build.gradle
File metadata and controls
175 lines (150 loc) · 5.98 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
// Dynamic versioning based on git context
def getVersionSuffix() {
def gitTag = System.getenv("GITHUB_REF_NAME")
def isTaggedRelease = System.getenv("GITHUB_REF_TYPE") == "tag"
def runNumber = System.getenv("GITHUB_RUN_NUMBER")
def branchName = System.getenv("GITHUB_REF_NAME")
if (isTaggedRelease) {
// Tagged release: use clean version (no suffix)
return ""
}
// Local build (no CI environment)
if (runNumber == null) {
try {
def gitBranch = "git rev-parse --abbrev-ref HEAD".execute().text.trim()
def gitHash = "git rev-parse --short HEAD".execute().text.trim()
def sanitizedBranch = gitBranch
.replaceAll(/[\/\\]/, '-')
.replaceAll(/[^a-zA-Z0-9\-.]/, '-')
.replaceAll(/--+/, '-')
.toLowerCase()
return "-${sanitizedBranch}.local+${gitHash}"
} catch (Exception e) {
return "-local.dev"
}
}
// CI build: use branch name + run number + commit hash
def gitHash = System.getenv("GITHUB_SHA")?.substring(0, 7) ?: "unknown"
def sanitizedBranch = branchName
.replaceAll(/[\/\\]/, '-')
.replaceAll(/[^a-zA-Z0-9\-.]/, '-')
.replaceAll(/--+/, '-')
.toLowerCase()
return "-${sanitizedBranch}.${runNumber}+${gitHash}"
}
// Get GitHub repository from git config or environment
def getGitHubRepository() {
// Try environment variable first (CI/CD)
def envRepo = System.getenv("GITHUB_REPOSITORY")
if (envRepo) return envRepo
// Fall back to git config
try {
def origin = 'git config --get remote.origin.url'.execute().text.trim()
// Handle both HTTPS and SSH URLs
// HTTPS: https://github.com/plug-obp/rege-java.git
// SSH: git@github.com:plug-obp/rege-java.git
def matcher = origin =~ /github\.com[:\/](.+?)(?:\.git)?$/
return matcher ? matcher[0][1] : 'plug-obp/obp3-core'
} catch (Exception e) {
return 'plug-obp/obp3-core'
}
}
// Apply dynamic version to all projects
def baseVersion = project.findProperty('version') ?: '1.0.0'
def fullVersion = "${baseVersion}${getVersionSuffix()}"
allprojects {
group = 'org.obpcdl'
version = fullVersion
}
// Make GitHub repository available to all projects
ext.githubRepo = getGitHubRepository()
// Configure publishing for all subprojects
subprojects {
apply plugin: 'java'
apply plugin: 'maven-publish'
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.quiet()
failOnError = false // Don't fail build on javadoc errors
}
java {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'org.obpcdl'
artifactId = project.name
from components.java
pom {
// name and description set in each subproject
url = "https://github.com/${rootProject.ext.githubRepo}"
licenses {
license {
name = 'MIT License'
url = 'https://opensource.org/licenses/MIT'
}
}
developers {
developer {
id = 'plug-obp'
name = 'OBPCDL'
}
}
scm {
connection = "scm:git:git://github.com/${rootProject.ext.githubRepo}.git"
developerConnection = "scm:git:ssh://github.com/${rootProject.ext.githubRepo}.git"
url = "https://github.com/${rootProject.ext.githubRepo}"
}
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/${rootProject.ext.githubRepo}")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
}
// Display computed version
gradle.projectsLoaded {
println("")
println("═══════════════════════════════════════════════════════════")
println(" 📦 Project: ${rootProject.name}")
println(" 🏷️ Version: ${fullVersion}")
println("═══════════════════════════════════════════════════════════")
println("")
}
repositories {
mavenCentral()
}
// Version validation task for tagged releases
tasks.register('validateTagVersion') {
doLast {
def gitTag = System.getenv("GITHUB_REF_NAME")
def isTaggedRelease = System.getenv("GITHUB_REF_TYPE") == "tag"
if (isTaggedRelease) {
// Extract version from tag (e.g., v1.0.0 → 1.0.0)
def tagVersion = gitTag.startsWith('v') ? gitTag.substring(1) : gitTag
def gradleVersion = baseVersion
if (tagVersion != gradleVersion) {
throw new GradleException(
"\n❌ Version mismatch!\n" +
" Git tag version: ${tagVersion}\n" +
" Gradle version: ${gradleVersion}\n" +
" \n" +
" Please ensure tag matches version in gradle.properties\n"
)
}
println("✅ Version validation passed: ${tagVersion}")
} else {
println("ℹ️ Not a tagged release, skipping version validation")
}
}
}