Skip to content

Commit 35b967a

Browse files
committed
Add opt-in build scan integration with Gradle Enterprise
This commit adds opt-in build scan integration with Gradle Enterprise. When the GRADLE_ENTERPRISE_URL environment variable is set on a developer's machine or on CI, a build scan will be automatically uploaded to Gradle Enterprise at the end of the build. This initial integration will establish a baseline for Spring Framework builds. Once that baseline has been established we can use the build scans to identify ways in which the build can be optimized and updated to make use of Gradle's build caching which should reduce build times, significantly so for changes that only affect tasks near the leaf nodes of the task graph.
1 parent 2b1ae4a commit 35b967a

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ plugins {
1212
id 'org.asciidoctor.convert' version '1.5.8'
1313
id 'io.spring.nohttp' version '0.0.3.RELEASE'
1414
id 'de.undercouch.download' version '4.0.0'
15+
id 'com.gradle.build-scan' version '2.4.1'
1516
id "com.jfrog.artifactory" version '4.9.8' apply false
1617
id "io.freefair.aspectj" version "4.0.0" apply false
1718
id "com.github.ben-manes.versions" version "0.24.0"
1819
}
1920

21+
if (System.getenv('GRADLE_ENTERPRISE_URL')) {
22+
apply from: "$rootDir/gradle/build-scan-user-data.gradle"
23+
buildScan {
24+
captureTaskInputFiles = true
25+
publishAlways()
26+
server = System.getenv('GRADLE_ENTERPRISE_URL')
27+
}
28+
}
29+
2030
ext {
2131
moduleProjects = subprojects.findAll { it.name.startsWith("spring-") }
2232
javaProjects = subprojects - project(":framework-bom")

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
version=5.2.0.BUILD-SNAPSHOT
2+
org.gradle.caching=false

gradle/build-scan-user-data.gradle

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
tagOs()
2+
tagIde()
3+
tagCiOrLocal()
4+
addCiMetadata()
5+
addGitMetadata()
6+
7+
void tagOs() {
8+
buildScan.tag System.getProperty('os.name')
9+
}
10+
11+
void tagIde() {
12+
if (System.getProperty('idea.version')) {
13+
buildScan.tag 'IntelliJ IDEA'
14+
} else if (System.getProperty('eclipse.buildId')) {
15+
buildScan.tag 'Eclipse'
16+
}
17+
}
18+
19+
void tagCiOrLocal() {
20+
buildScan.tag(isCi() ? 'CI' : 'LOCAL')
21+
}
22+
23+
void addGitMetadata() {
24+
buildScan.background {
25+
def gitCommitId = execAndGetStdout('git', 'rev-parse', '--short=8', '--verify', 'HEAD')
26+
def gitBranchName = execAndGetStdout('git', 'rev-parse', '--abbrev-ref', 'HEAD')
27+
def gitStatus = execAndGetStdout('git', 'status', '--porcelain')
28+
29+
if(gitCommitId) {
30+
def commitIdLabel = 'Git Commit ID'
31+
value commitIdLabel, gitCommitId
32+
link 'Git commit build scans', customValueSearchUrl([(commitIdLabel): gitCommitId])
33+
}
34+
if (gitBranchName) {
35+
tag gitBranchName
36+
value 'Git branch', gitBranchName
37+
}
38+
if (gitStatus) {
39+
tag 'dirty'
40+
value 'Git status', gitStatus
41+
}
42+
}
43+
}
44+
45+
void addCiMetadata() {
46+
def ciBuild = 'CI BUILD'
47+
if (System.getenv('bamboo.resultsUrl')) {
48+
buildScan.link ciBuild, System.getenv('bamboo.resultsUrl')
49+
}
50+
}
51+
52+
boolean isCi() {
53+
System.getenv('bamboo.resultsUrl')
54+
}
55+
56+
String execAndGetStdout(String... args) {
57+
def stdout = new ByteArrayOutputStream()
58+
exec {
59+
commandLine(args)
60+
standardOutput = stdout
61+
}
62+
return stdout.toString().trim()
63+
}
64+
65+
String customValueSearchUrl(Map<String, String> search) {
66+
def query = search.collect { name, value ->
67+
"search.names=${encodeURL(name)}&search.values=${encodeURL(value)}"
68+
}.join('&')
69+
70+
"$buildScan.server/scans?$query"
71+
}
72+
73+
String encodeURL(String url){
74+
URLEncoder.encode(url, 'UTF-8')
75+
}

0 commit comments

Comments
 (0)