|
1 |
| -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
| 1 | +import org.apache.tools.ant.taskdefs.condition.Os |
2 | 2 |
|
3 | 3 | plugins {
|
4 |
| - id 'org.springframework.boot' version '2.7.18' |
5 | 4 | id 'java'
|
6 |
| - id 'org.jetbrains.kotlin.jvm' version '1.7.21' |
7 |
| - id "com.github.ben-manes.versions" version "0.51.0" |
| 5 | + id 'org.springframework.boot' version '3.3.2' |
| 6 | + id 'io.spring.dependency-management' version '1.1.6' |
8 | 7 | }
|
9 | 8 |
|
10 |
| -apply plugin: 'io.spring.dependency-management' |
| 9 | +apply plugin: 'java' |
| 10 | + |
| 11 | +ext { |
| 12 | + newrelic_version = '8.15.0' |
| 13 | +} |
11 | 14 |
|
12 | 15 | group = 'org.springframework.samples'
|
13 | 16 | version = '1.0.0'
|
14 |
| -sourceCompatibility = JavaVersion.VERSION_17 |
15 |
| -targetCompatibility = JavaVersion.VERSION_17 |
16 |
| - |
17 |
| -tasks.withType(KotlinCompile) { |
18 |
| - kotlinOptions.jvmTarget = JavaVersion.VERSION_17 |
19 |
| -} |
20 | 17 |
|
21 | 18 | repositories {
|
22 | 19 | mavenCentral()
|
23 | 20 | }
|
24 | 21 |
|
25 |
| -ext.webjarsFontawesomeVersion = "4.7.0" |
26 |
| -ext.webjarsBootstrapVersion = "5.1.3" |
27 |
| - |
28 | 22 | dependencies {
|
| 23 | + implementation 'io.micrometer:micrometer-core' |
29 | 24 | implementation 'org.springframework.boot:spring-boot-starter-cache'
|
30 | 25 | implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
31 | 26 | implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
32 | 27 | implementation 'org.springframework.boot:spring-boot-starter-web'
|
33 | 28 | implementation 'org.springframework.boot:spring-boot-starter-validation'
|
34 |
| - implementation 'org.springframework.boot:spring-boot-starter-aop' |
35 | 29 | implementation 'javax.cache:cache-api'
|
| 30 | + implementation 'jakarta.xml.bind:jakarta.xml.bind-api' |
| 31 | + implementation 'jakarta.annotation:jakarta.annotation-api' |
| 32 | + implementation "com.newrelic.agent.java:newrelic-api:$newrelic_version" |
| 33 | + |
36 | 34 | runtimeOnly 'org.springframework.boot:spring-boot-starter-actuator'
|
37 |
| - runtimeOnly 'org.webjars:webjars-locator-core' |
38 |
| - runtimeOnly "org.webjars.npm:bootstrap:${webjarsBootstrapVersion}" |
39 |
| - runtimeOnly "org.webjars.npm:font-awesome:${webjarsFontawesomeVersion}" |
40 |
| - runtimeOnly 'org.ehcache:ehcache' |
| 35 | + runtimeOnly 'com.github.ben-manes.caffeine:caffeine' |
41 | 36 | runtimeOnly 'com.h2database:h2'
|
42 |
| - runtimeOnly 'mysql:mysql-connector-java:8.0.28' |
43 |
| - runtimeOnly 'org.postgresql:postgresql' |
44 |
| - implementation 'org.apache.httpcomponents:httpclient:4.5.13' |
45 |
| - implementation 'com.newrelic.agent.java:newrelic-api:8.14.0' |
46 |
| - implementation 'io.micrometer:micrometer-core:1.10.3' |
47 | 37 |
|
48 |
| - // developmentOnly 'com.newrelic.agent.java:newrelic-java:7.8.0' |
49 | 38 | developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
50 |
| - testImplementation 'org.springframework.boot:spring-boot-starter-test' |
51 | 39 | }
|
52 | 40 |
|
53 |
| -tasks.named('test') { |
54 |
| - useJUnitPlatform() |
| 41 | +build { |
| 42 | + dependsOn 'buildFrontEnd' |
| 43 | + mustRunAfter 'buildFrontEnd' |
55 | 44 | }
|
56 | 45 |
|
57 | 46 | bootRun {
|
58 |
| - jvmArgs = ["-javaagent:${projectDir}/newrelic/newrelic.jar"] |
| 47 | + dependsOn 'downloadNewRelicAgent', 'buildFrontEnd', 'build' |
| 48 | + mustRunAfter 'downloadNewRelicAgent', 'buildFrontEnd', 'build' |
| 49 | + |
| 50 | + jvmArgs = ["-javaagent:${projectDir}/newrelic/newrelic-v${newrelic_version}.jar"] |
| 51 | +} |
| 52 | + |
| 53 | +tasks.register('buildFrontEnd', DefaultTask) { |
| 54 | + group 'New Relic' |
| 55 | + doFirst { |
| 56 | + exec { |
| 57 | + String cmd = 'npm' |
| 58 | + if (Os.isFamily(Os.FAMILY_WINDOWS)) { |
| 59 | + cmd = "npm.cmd" |
| 60 | + } |
| 61 | + |
| 62 | + workingDir "$rootDir/client" |
| 63 | + commandLine cmd, 'run', 'build' |
| 64 | + } |
| 65 | + |
| 66 | + delete 'src/main/resources/static/react' |
| 67 | + |
| 68 | + copy { |
| 69 | + from "client/dist" |
| 70 | + into "src/main/resources/static/react" |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + doLast { |
| 75 | + def newRelicLicenseKey = System.getenv('BROWSER_LICENSE_KEY') |
| 76 | + def newRelicAccountId = System.getenv('BROWSER_ACCOUNT_ID') |
| 77 | + def newRelicTrustKey = System.getenv('BROWSER_TRUST_KEY') |
| 78 | + def newRelicAgentId = System.getenv('BROWSER_AGENT_ID') |
| 79 | + def newRelicApplicationId = System.getenv('BROWSER_APPLICATION_ID') |
| 80 | + |
| 81 | + if (newRelicTrustKey == null && newRelicAccountId != null) { |
| 82 | + newRelicTrustKey = newRelicAccountId |
| 83 | + } |
| 84 | + |
| 85 | + if (newRelicAgentId == null && newRelicApplicationId != null) { |
| 86 | + newRelicAgentId = newRelicApplicationId |
| 87 | + } |
| 88 | + |
| 89 | + if (newRelicLicenseKey == null || newRelicAccountId == null || newRelicTrustKey == null || newRelicAgentId == null || newRelicApplicationId == null) { |
| 90 | + throw new GradleException('BROWSER_* ENVIRONMENT VARIABLES NOT SET') |
| 91 | + } |
| 92 | + |
| 93 | + def templateJavaScript = file("$rootDir/browserMonitoringTemplate.js") |
| 94 | + def indexFile = file("$rootDir/src/main/resources/static/react/index.html") |
| 95 | + |
| 96 | + def indexFileContents = indexFile.getText() |
| 97 | + def templateContents = templateJavaScript.getText() |
| 98 | + |
| 99 | + templateContents = templateContents.replace("{{NEW_RELIC_APPLICATION_ID}}", newRelicApplicationId) |
| 100 | + templateContents = templateContents.replace("{{NEW_RELIC_AGENT_ID}}", newRelicAgentId) |
| 101 | + templateContents = templateContents.replace("{{NEW_RELIC_ACCOUNT_ID}}", newRelicAccountId) |
| 102 | + templateContents = templateContents.replace("{{NEW_RELIC_TRUST_KEY}}", newRelicTrustKey) |
| 103 | + templateContents = templateContents.replace("{{NEW_RELIC_LICENSE_KEY}}", newRelicLicenseKey) |
| 104 | + |
| 105 | + templateContents = "<script type=\"text/javascript\">\n" + templateContents + "\n</script>" |
| 106 | + def newIndexFileContent = indexFileContents.replace("<script id=\"new-relic-template\"><!-- FILLED OUT DURING BUILD --></script>", templateContents) |
| 107 | + |
| 108 | + indexFile.write(newIndexFileContent) |
| 109 | + } |
| 110 | + |
| 111 | + outputs.file('src/main/resources/static/react/index.html') |
| 112 | + outputs.dir('src/main/resources/static/react/assets') |
| 113 | +} |
| 114 | + |
| 115 | +tasks.register('downloadNewRelicAgent', DefaultTask) { |
| 116 | + group 'New Relic' |
| 117 | + |
| 118 | + onlyIf { |
| 119 | + def agentExists = file("newrelic/newrelic-v${newrelic_version}.jar").exists() |
| 120 | + def agentDoesNotExist = !agentExists |
| 121 | + |
| 122 | + if (agentDoesNotExist) { |
| 123 | + println "Downloading New Relic Java Agent v${newrelic_version}..." |
| 124 | + } else { |
| 125 | + println "Found Local Java Agent v${newrelic_version}; Skipping Task (delete " + |
| 126 | + "newrelic-v${newrelic_version}.jar to force the download again)" |
| 127 | + } |
| 128 | + |
| 129 | + return agentDoesNotExist |
| 130 | + } |
| 131 | + |
| 132 | + doFirst { |
| 133 | + mkdir 'newrelic' |
| 134 | + delete(fileTree("newrelic") { |
| 135 | + include("**/newrelic-v*.jar") |
| 136 | + }) |
| 137 | + |
| 138 | + def fileUrl = "https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java-${newrelic_version}.zip" |
| 139 | + def destinationFile = file("$rootDir/newrelic/newrelic.zip") |
| 140 | + |
| 141 | + new URL(fileUrl).withInputStream { inputStream -> |
| 142 | + destinationFile.withOutputStream { outputStream -> |
| 143 | + outputStream << inputStream |
| 144 | + } |
| 145 | + } |
| 146 | + } |
| 147 | + |
| 148 | + doLast { |
| 149 | + copy { |
| 150 | + from zipTree(file('newrelic/newrelic.zip')) |
| 151 | + into rootDir |
| 152 | + exclude("newrelic/newrelic.yml") |
| 153 | + exclude("newrelic/LICENSE") |
| 154 | + exclude("newrelic/THIRD_PARTY_NOTICES.md") |
| 155 | + exclude("newrelic/extension-example.xml") |
| 156 | + exclude("newrelic/newrelic-api.jar") |
| 157 | + exclude("newrelic/newrelic-api-javadoc.jar") |
| 158 | + exclude("newrelic/newrelic-api-sources.jar") |
| 159 | + } |
| 160 | + |
| 161 | + file("newrelic/newrelic.jar").renameTo("newrelic/newrelic-v${newrelic_version}.jar") |
| 162 | + |
| 163 | + delete("newrelic/newrelic.zip") |
| 164 | + } |
59 | 165 | }
|
0 commit comments