-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.gradle
More file actions
135 lines (119 loc) · 3.44 KB
/
Copy pathbuild.gradle
File metadata and controls
135 lines (119 loc) · 3.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
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 runGit(List<String> arguments) {
def stdout = new StringBuilder()
def stderr = new StringBuilder()
def process = (['git'] + arguments).execute()
process.waitForProcessOutput(stdout, stderr)
return [exitValue: process.exitValue(), output: stdout.toString().trim()]
}
def generateVersion() {
// Check if workspace is clean
def gitStatus = runGit(['status', '--porcelain']).output
def isDirty = !gitStatus.isEmpty()
// Get current commit SHA (short version)
def gitSha = runGit(['rev-parse', '--short', 'HEAD']).output
// Check if we're currently on a tag
def currentTag = null
try {
def currentTagResult = runGit(['describe', '--exact-match', '--tags', 'HEAD'])
if (currentTagResult.exitValue == 0) {
currentTag = currentTagResult.output
}
} 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 mostRecentTagResult = runGit(['describe', '--tags', '--abbrev=0'])
if (mostRecentTagResult.exitValue == 0) {
mostRecentTag = mostRecentTagResult.output
}
} 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'
}