-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
165 lines (130 loc) · 5.74 KB
/
build.gradle
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
import org.apache.tools.ant.taskdefs.condition.Os
plugins {
id 'java'
id 'org.springframework.boot' version '3.3.2'
id 'io.spring.dependency-management' version '1.1.6'
}
apply plugin: 'java'
ext {
newrelic_version = '8.15.0'
}
group = 'org.springframework.samples'
version = '1.0.0'
repositories {
mavenCentral()
}
dependencies {
implementation 'io.micrometer:micrometer-core'
implementation 'org.springframework.boot:spring-boot-starter-cache'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'javax.cache:cache-api'
implementation 'jakarta.xml.bind:jakarta.xml.bind-api'
implementation 'jakarta.annotation:jakarta.annotation-api'
implementation "com.newrelic.agent.java:newrelic-api:$newrelic_version"
runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
runtimeOnly 'com.github.ben-manes.caffeine:caffeine'
runtimeOnly 'com.h2database:h2'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}
build {
dependsOn 'buildFrontEnd'
mustRunAfter 'buildFrontEnd'
}
bootRun {
dependsOn 'downloadNewRelicAgent', 'buildFrontEnd', 'build'
mustRunAfter 'downloadNewRelicAgent', 'buildFrontEnd', 'build'
jvmArgs = ["-javaagent:${projectDir}/newrelic/newrelic-v${newrelic_version}.jar"]
}
tasks.register('buildFrontEnd', DefaultTask) {
group 'New Relic'
doFirst {
exec {
String cmd = 'npm'
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
cmd = "npm.cmd"
}
workingDir "$rootDir/client"
commandLine cmd, 'run', 'build'
}
delete 'src/main/resources/static/react'
copy {
from "client/dist"
into "src/main/resources/static/react"
}
}
doLast {
def newRelicLicenseKey = System.getenv('BROWSER_LICENSE_KEY')
def newRelicAccountId = System.getenv('BROWSER_ACCOUNT_ID')
def newRelicTrustKey = System.getenv('BROWSER_TRUST_KEY')
def newRelicAgentId = System.getenv('BROWSER_AGENT_ID')
def newRelicApplicationId = System.getenv('BROWSER_APPLICATION_ID')
if (newRelicTrustKey == null && newRelicAccountId != null) {
newRelicTrustKey = newRelicAccountId
}
if (newRelicAgentId == null && newRelicApplicationId != null) {
newRelicAgentId = newRelicApplicationId
}
if (newRelicLicenseKey == null || newRelicAccountId == null || newRelicTrustKey == null || newRelicAgentId == null || newRelicApplicationId == null) {
throw new GradleException('BROWSER_* ENVIRONMENT VARIABLES NOT SET')
}
def templateJavaScript = file("$rootDir/browserMonitoringTemplate.js")
def indexFile = file("$rootDir/src/main/resources/static/react/index.html")
def indexFileContents = indexFile.getText()
def templateContents = templateJavaScript.getText()
templateContents = templateContents.replace("{{NEW_RELIC_APPLICATION_ID}}", newRelicApplicationId)
templateContents = templateContents.replace("{{NEW_RELIC_AGENT_ID}}", newRelicAgentId)
templateContents = templateContents.replace("{{NEW_RELIC_ACCOUNT_ID}}", newRelicAccountId)
templateContents = templateContents.replace("{{NEW_RELIC_TRUST_KEY}}", newRelicTrustKey)
templateContents = templateContents.replace("{{NEW_RELIC_LICENSE_KEY}}", newRelicLicenseKey)
templateContents = "<script type=\"text/javascript\">\n" + templateContents + "\n</script>"
def newIndexFileContent = indexFileContents.replace("<script id=\"new-relic-template\"><!-- FILLED OUT DURING BUILD --></script>", templateContents)
indexFile.write(newIndexFileContent)
}
outputs.file('src/main/resources/static/react/index.html')
outputs.dir('src/main/resources/static/react/assets')
}
tasks.register('downloadNewRelicAgent', DefaultTask) {
group 'New Relic'
onlyIf {
def agentExists = file("newrelic/newrelic-v${newrelic_version}.jar").exists()
def agentDoesNotExist = !agentExists
if (agentDoesNotExist) {
println "Downloading New Relic Java Agent v${newrelic_version}..."
} else {
println "Found Local Java Agent v${newrelic_version}; Skipping Task (delete " +
"newrelic-v${newrelic_version}.jar to force the download again)"
}
return agentDoesNotExist
}
doFirst {
mkdir 'newrelic'
delete(fileTree("newrelic") {
include("**/newrelic-v*.jar")
})
def fileUrl = "https://download.newrelic.com/newrelic/java-agent/newrelic-agent/${newrelic_version}/newrelic-java-${newrelic_version}.zip"
def destinationFile = file("$rootDir/newrelic/newrelic.zip")
new URL(fileUrl).withInputStream { inputStream ->
destinationFile.withOutputStream { outputStream ->
outputStream << inputStream
}
}
}
doLast {
copy {
from zipTree(file('newrelic/newrelic.zip'))
into rootDir
exclude("newrelic/newrelic.yml")
exclude("newrelic/LICENSE")
exclude("newrelic/THIRD_PARTY_NOTICES.md")
exclude("newrelic/extension-example.xml")
exclude("newrelic/newrelic-api.jar")
exclude("newrelic/newrelic-api-javadoc.jar")
exclude("newrelic/newrelic-api-sources.jar")
}
file("newrelic/newrelic.jar").renameTo("newrelic/newrelic-v${newrelic_version}.jar")
delete("newrelic/newrelic.zip")
}
}