-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.gradle
More file actions
133 lines (118 loc) · 3.43 KB
/
build.gradle
File metadata and controls
133 lines (118 loc) · 3.43 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
plugins {
id 'idea'
id 'eclipse'
id 'com.diffplug.spotless' version '6.25.0' apply false
id 'io.freefair.lombok' version '9.2.0' apply false
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
eclipse {
classpath {
downloadSources = true
downloadJavadoc = true
}
}
version = generateVersion()
group = 'dev.braintrust'
ext {
otelVersion = '1.59.0'
jacksonVersion = '2.16.1'
junitVersion = '5.11.4'
slf4jVersion = '2.0.17'
}
/**
* Use git to compute the sdk version
*
* This is written into braintrust.properties at build time and shipped into the distributed sdk jar
*
* - if we are on a tag (i.e. v0.0.3), use the tag WITHOUT the 'v' prefix (0.0.3)
* - otherwise, use $mostRecentTag-$currentCommitSha (without 'v' prefix)
*
* Additionally, if the git workspace is not clean, append -DIRTY to the version
*
* Examples
* - 0.0.3 (from tag v0.0.3)
* - 0.0.3-c4af682 (from tag v0.0.3)
* - 0.0.3-c4af682-DIRTY
*/
def generateVersion() {
// Check if workspace is clean
def gitStatusProcess = ['git', 'status', '--porcelain'].execute()
gitStatusProcess.waitFor()
def gitStatus = gitStatusProcess.text.trim()
def isDirty = !gitStatus.isEmpty()
// Get current commit SHA (short version)
def gitShaProcess = ['git', 'rev-parse', '--short', 'HEAD'].execute()
gitShaProcess.waitFor()
def gitSha = gitShaProcess.text.trim()
// Check if we're currently on a tag
def currentTag = null
try {
def currentTagProcess = ['git', 'describe', '--exact-match', '--tags', 'HEAD'].execute()
currentTagProcess.waitFor()
if (currentTagProcess.exitValue() == 0) {
currentTag = currentTagProcess.text.trim()
}
} catch (Exception e) {
// Not on a tag, that's fine
}
def version
if (currentTag != null) {
// We're on a tag, use the tag name (strip 'v' prefix if present)
version = currentTag.startsWith('v') ? currentTag.substring(1) : currentTag
} else {
// Not on a tag, find the most recent tag
def mostRecentTag = null
try {
def mostRecentTagProcess = ['git', 'describe', '--tags', '--abbrev=0'].execute()
mostRecentTagProcess.waitFor()
if (mostRecentTagProcess.exitValue() == 0) {
mostRecentTag = mostRecentTagProcess.text.trim()
}
} catch (Exception e) {
// No tags found, use just the SHA
mostRecentTag = null
}
if (mostRecentTag != null) {
// Strip 'v' prefix if present
def cleanTag = mostRecentTag.startsWith('v') ? mostRecentTag.substring(1) : mostRecentTag
version = "${cleanTag}-${gitSha}"
} else {
version = gitSha
}
}
// Append -DIRTY if workspace is not clean
if (isDirty) {
version = "${version}-DIRTY"
}
return version
}
subprojects {
pluginManager.withPlugin('java') {
apply plugin: 'com.diffplug.spotless'
apply plugin: 'io.freefair.lombok'
dependencies {
compileOnly 'com.google.auto.service:auto-service-annotations:1.1.1'
annotationProcessor 'com.google.auto.service:auto-service:1.1.1'
}
spotless {
java {
target 'src/*/java/**/*.java'
googleJavaFormat('1.19.2').aosp().reflowLongStrings()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
}
}
// Task to install git hooks
task installGitHooks(type: Exec) {
description = 'Install git hooks for code formatting'
group = 'Build Setup'
commandLine 'bash', 'scripts/install-hooks.sh'
}