Skip to content

Commit efc8469

Browse files
committed
Modernize Gradle build: upgrade to 8.5, use Maven for agent deps
- Replace root build.gradle with standardized template (verify plugin 4.0, Maven-based agent resolution) - Create gradle.properties with java.agent.version=8.6.0 - Upgrade Gradle wrapper from 7.3 to 8.5 - Rename rootProject.name from java-instrumentation-template to apache-axis2-instrumentation - Update all module build.gradle files to use project.findProperty('java.agent.version') - Add agent-bridge dependency to all modules - Replace sourceCompatibility/targetCompatibility with Java toolchain - Change passes to passesOnly, compile to implementation in verify blocks - Widen axis2-kernel range to [1.4,1.5) since 1.4 and 1.4.1 have identical classes - apache-axis2-2.0 module uses Java 17 toolchain - Remove newrelic-dependencies.sh (no longer needed) - Update release.yml: remove newrelic-dependencies.sh call, upgrade JDK to 21
1 parent f870349 commit efc8469

8 files changed

Lines changed: 133 additions & 215 deletions

File tree

.github/workflows/release.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ jobs:
1818
fetch-depth: 0
1919

2020

21-
- name: Set up JDK 17
21+
- name: Set up JDK 21
2222
uses: actions/setup-java@v3
2323
with:
24-
java-version: 17
24+
java-version: 21
2525
distribution: 'temurin'
2626

2727

@@ -35,7 +35,6 @@ jobs:
3535
3636
- name: Build with Gradle and verifyInstrumentation
3737
run: |
38-
. ./newrelic-dependencies.sh
3938
./gradlew clean build install verifyInstrumentation
4039
4140
- name: Identify Release Type

apache-axis2-2.0/build.gradle

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44
apply plugin: 'java'
55

66
java {
7-
sourceCompatibility = JavaVersion.VERSION_17
8-
targetCompatibility = JavaVersion.VERSION_17
7+
toolchain {
8+
languageVersion = JavaLanguageVersion.of(17)
9+
}
910
}
1011

1112
dependencies {
1213
implementation 'org.apache.axis2:axis2-kernel:2.0.0'
1314
implementation 'org.apache.axis2:axis2-transport-http:2.0.0'
1415
implementation 'jakarta.servlet:jakarta.servlet-api:6.0.0'
1516

16-
// New Relic Labs Java Agent dependencies
17-
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0'
18-
implementation 'com.newrelic.agent.java:newrelic-api:6.4.0'
19-
implementation fileTree(include: ['*.jar'], dir: '../libs')
17+
// New Relic Java Agent dependencies
18+
implementation 'com.newrelic.agent.java:newrelic-agent:' + project.findProperty('java.agent.version')
19+
implementation 'com.newrelic.agent.java:newrelic-api:' + project.findProperty('java.agent.version')
20+
implementation 'com.newrelic.agent.java:agent-bridge:' + project.findProperty('java.agent.version')
2021
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
2122
}
2223

@@ -30,7 +31,7 @@ jar {
3031
}
3132

3233
verifyInstrumentation {
33-
passes ('org.apache.axis2:axis2-transport-http:[2.0.0,)') {
34-
compile( 'jakarta.servlet:jakarta.servlet-api:6.0.0')
34+
passesOnly ('org.apache.axis2:axis2-transport-http:[2.0.0,)') {
35+
implementation('jakarta.servlet:jakarta.servlet-api:6.0.0')
3536
}
3637
}

apache-axis2/build.gradle

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ dependencies {
77
// https://mvnrepository.com/artifact/org.apache.axis2/axis2
88
implementation 'org.apache.axis2:axis2-kernel:1.4.1'
99

10-
11-
// New Relic Labs Java Agent dependencies
12-
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0'
13-
implementation 'com.newrelic.agent.java:newrelic-api:6.4.0'
14-
implementation fileTree(include: ['*.jar'], dir: '../libs')
10+
// New Relic Java Agent dependencies
11+
implementation 'com.newrelic.agent.java:newrelic-agent:' + project.findProperty('java.agent.version')
12+
implementation 'com.newrelic.agent.java:newrelic-api:' + project.findProperty('java.agent.version')
13+
implementation 'com.newrelic.agent.java:agent-bridge:' + project.findProperty('java.agent.version')
1514
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
1615
}
1716

@@ -25,6 +24,6 @@ jar {
2524
}
2625

2726
verifyInstrumentation {
28-
passes 'org.apache.axis2:axis2-kernel:[1.4.1,1.5)'
29-
passes 'org.apache.axis2:axis2-transport-http:[1.5,2.0.0)'
27+
passesOnly 'org.apache.axis2:axis2-kernel:[1.4,1.5)'
28+
passesOnly 'org.apache.axis2:axis2-transport-http:[1.5,2.0.0)'
3029
}

build.gradle

Lines changed: 113 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -3,113 +3,85 @@
33

44
// Global defaults - override here or in individual modules as needed.
55
buildscript {
6-
repositories {
7-
flatDir dirs: 'template-lib'
8-
mavenLocal()
9-
mavenCentral()
10-
gradlePluginPortal()
11-
}
12-
13-
dependencies {
14-
classpath 'gradle-templates:gradle-templates:1.5'
15-
classpath 'com.newrelic.agent.java:gradle-verify-instrumentation-plugin:3.2'
16-
}
17-
}
6+
repositories {
7+
flatDir dirs: 'template-lib'
8+
mavenLocal()
9+
mavenCentral()
10+
gradlePluginPortal()
11+
}
1812

19-
plugins {
20-
id "de.undercouch.download" version "5.0.0"
13+
dependencies {
14+
classpath 'gradle-templates:gradle-templates:1.5'
15+
classpath 'com.newrelic.agent.java:gradle-verify-instrumentation-plugin:4.0'
16+
}
2117
}
2218

2319
project.ext {
24-
group = 'com.newrelic.instrumentation.labs'
25-
javaAgentVersion = '6.4.0'
20+
group = 'com.newrelic.instrumentation.labs'
21+
javaAgentVersion = project.findProperty('java.agent.version')
2622

27-
// Aligned with minimum Java major version supported by latest Java Agent
28-
javaVersion = JavaVersion.VERSION_1_8
23+
// Aligned with minimum Java major version supported by latest Java Agent
24+
javaVersion = JavaVersion.VERSION_1_8
2925

3026
}
3127

3228
apply plugin: 'java'
33-
apply plugin: 'de.undercouch.download'
34-
35-
import templates.*
36-
import de.undercouch.gradle.tasks.download.Download
37-
38-
task getAgent(type: Download) {
39-
def rootProject = projectDir.path
40-
src 'https://repo1.maven.org/maven2/com/newrelic/agent/java/newrelic-agent/'+project.javaAgentVersion+'/newrelic-agent-'+project.javaAgentVersion+'.jar'
41-
dest projectDir.path+"/libs/newrelic-agent-"+project.javaAgentVersion+".jar"
42-
}
4329

44-
task extractJars(type: Copy) {
4530

46-
from zipTree(projectDir.path+"/libs/newrelic-agent-"+project.javaAgentVersion+".jar")
47-
into projectDir.path+"/libs"
48-
}
31+
import templates.ProjectTemplate
32+
import templates.TemplatesPlugin
4933

50-
task cleanUp(type: Delete) {
51-
delete projectDir.path+'/libs/META-INF', projectDir.path+'/libs/com', projectDir.path+'/libs/mozilla'
52-
delete projectDir.path+'/libs/LICENSE', projectDir.path+'/libs/Log4j-events.dtd', projectDir.path+'/libs/THIRD_PARTY_NOTICES.md'
53-
delete fileTree(projectDir.path+'/libs') {
54-
include '**/*.xsd'
55-
include '**/*.xml'
56-
include '**/*.yml'
57-
include '**/*.properties'
58-
}
59-
}
34+
tasks.register('UpdateAgentVersion') {
35+
def matchingFiles = fileTree(dir: ".", include: "**/build.gradle")
36+
def rootPath = rootDir.absolutePath
37+
def rootBuildPath = "${rootPath}/build.gradle"
38+
def agentVersionString = "com.newrelic.agent.java:newrelic-agent:" + javaAgentVersion
6039

61-
task checkForDependencies(type: Exec) {
62-
environment "JAVAAGENTVERSION", javaAgentVersion
63-
def rootProject = projectDir.path
64-
def cmdLine = rootProject+'/newrelic-dependencies.sh'
65-
workingDir rootProject
66-
commandLine cmdLine
67-
68-
}
40+
matchingFiles.each { matchingFile ->
41+
if (matchingFile.absolutePath != rootBuildPath) {
42+
if(!matchingFile.text.contains(agentVersionString)) {
6943

70-
task buildIfNeeded {
71-
dependsOn checkForDependencies
72-
dependsOn jar
73-
tasks.findByName('jar').mustRunAfter 'checkForDependencies'
44+
}
45+
}
46+
}
7447
}
7548

76-
task createModule {
77-
dependsOn checkForDependencies
78-
description = 'Generate project files for a new instrumentation module'
79-
group = 'New Relic Labs'
80-
doLast {
49+
tasks.register('createModule') {
50+
description = 'Generate project files for a new instrumentation module'
51+
group = 'New Relic Labs'
52+
doLast {
8153

82-
def rootProject = projectDir.path
54+
def rootProject = projectDir.path
8355

84-
String projectGroup = TemplatesPlugin.prompt('Instrumentation Module Group (default: ' + project.ext.group + ') (Hit return to use default):\n')
85-
String projectName = TemplatesPlugin.prompt('Instrumentation Module Name:\n')
56+
String projectGroup = TemplatesPlugin.prompt('Instrumentation Module Group (default: ' + project.ext.group + ') (Hit return to use default):\n')
57+
String projectName = TemplatesPlugin.prompt('Instrumentation Module Name:\n')
8658

87-
if (projectName == null) {
88-
throw new Exception("Please specify a valid module name.")
89-
} else {
90-
projectName = projectName.trim()
91-
}
59+
if (projectName == null) {
60+
throw new Exception("Please specify a valid module name.")
61+
} else {
62+
projectName = projectName.trim()
63+
}
9264

93-
if (projectGroup == null || projectGroup.trim() == '') {
94-
projectGroup = project.ext.group
95-
} else {
96-
projectGroup = projectGroup.trim()
97-
}
65+
if (projectGroup == null || projectGroup.trim() == '') {
66+
projectGroup = project.ext.group
67+
} else {
68+
projectGroup = projectGroup.trim()
69+
}
9870

99-
def projectLibDir = new File(rootProject+'/lib')
71+
def projectLibDir = new File(rootProject + '/lib')
10072

101-
def projectPath = new File(projectName)
102-
if (projectPath.exists()) {
103-
throw new Exception(projectPath.path + ' already exists.')
104-
}
73+
def projectPath = new File(projectName)
74+
if (projectPath.exists()) {
75+
throw new Exception(projectPath.path + ' already exists.')
76+
}
10577

106-
def projectJava = new File(projectPath, 'src/main/java')
107-
def projectTest = new File(projectPath, 'src/test/java')
108-
mkdir projectJava
109-
mkdir projectTest
78+
def projectJava = new File(projectPath, 'src/main/java')
79+
def projectTest = new File(projectPath, 'src/test/java')
80+
mkdir projectJava
81+
mkdir projectTest
11082

111-
ProjectTemplate.fromRoot(projectPath) {
112-
'build.gradle' '''
83+
ProjectTemplate.fromRoot(projectPath) {
84+
'build.gradle' '''
11385
// Build.gradle generated for instrumentation module PROJECT_NAME
11486
11587
apply plugin: 'java'
@@ -120,9 +92,9 @@ task createModule {
12092
// implementation 'javax.servlet:servlet-api:2.5'
12193
12294
// New Relic Labs Java Agent dependencies
123-
implementation 'com.newrelic.agent.java:newrelic-agent:JAVA_AGENT_VERSION'
124-
implementation 'com.newrelic.agent.java:newrelic-api:JAVA_AGENT_VERSION'
125-
implementation fileTree(include: ['*.jar'], dir: '../libs')
95+
implementation 'com.newrelic.agent.java:newrelic-agent:' + project.findProperty('java.agent.version')
96+
implementation 'com.newrelic.agent.java:newrelic-api:' + project.findProperty('java.agent.version')
97+
implementation 'com.newrelic.agent.java:agent-bridge:' + project.findProperty('java.agent.version')
12698
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
12799
}
128100
@@ -142,63 +114,62 @@ task createModule {
142114
// passes 'javax.servlet:servlet-api:[2.2,2.5]'
143115
// exclude 'javax.servlet:servlet-api:2.4.public_draft'
144116
}'''.replace('PROJECT_GROUP', projectGroup)
145-
.replace('PROJECT_NAME', projectName)
146-
.replace('PROJECT_PATH', projectPath.path)
147-
.replace('JAVA_AGENT_VERSION', project.ext.javaAgentVersion)
148-
}
149-
150-
File settings = new File('settings.gradle')
151-
settings.append("include '$projectName'\n")
152-
println "Created module in $projectPath.path."
153-
}
117+
.replace('PROJECT_NAME', projectName)
118+
.replace('PROJECT_PATH', projectPath.path)
119+
.replace('JAVA_AGENT_VERSION', project.ext.javaAgentVersion)
120+
}
121+
122+
File settings = new File('settings.gradle')
123+
settings.append("include '$projectName'\n")
124+
println "Created module in $projectPath.path."
125+
}
154126
}
155127

156128
subprojects {
157-
repositories {
158-
mavenLocal()
159-
mavenCentral()
160-
}
161-
162-
apply plugin: 'java'
163-
apply plugin: 'eclipse'
164-
apply plugin: 'idea'
165-
apply plugin: 'com.newrelic.gradle-verify-instrumentation-plugin'
166-
167-
sourceCompatibility = project.javaVersion
168-
targetCompatibility = project.javaVersion
169-
170-
dependencies {
171-
testImplementation fileTree(dir: '../lib', include: "*.jar") // + project.javaAgentVersion
172-
testImplementation 'org.nanohttpd:nanohttpd:2.3.1'
173-
testImplementation 'com.newrelic.agent.java:newrelic-agent:' + project.javaAgentVersion
174-
}
175-
176-
task install(dependsOn: buildIfNeeded, type: Copy) {
177-
description = 'Copies compiled jar to the NEW_RELIC_EXTENSIONS_DIR.'
178-
group = 'New Relic Labs'
179-
180-
def extDir = System.getenv("NEW_RELIC_EXTENSIONS_DIR") ?: " "
181-
182-
from jar
183-
into extDir
184-
}
185-
186-
compileJava.doFirst {
187-
tasks.findByName('checkForDependencies')
188-
}
189-
190-
install.doFirst {
191-
def extDir = System.getenv("NEW_RELIC_EXTENSIONS_DIR")
192-
if (extDir == null) {
193-
throw new Exception("Must set NEW_RELIC_EXTENSIONS_DIR.")
194-
}
195-
196-
if (extDir.startsWith("~" + File.separator)) {
197-
extDir = System.getProperty("user.home") + extDir.substring(1);
198-
}
199-
200-
if (!file(extDir).directory) {
201-
throw new Exception(extDir + "NEW_RELIC_EXTENSIONS_DIR, set as '" + extDir + "'is not a valid directory.")
202-
}
203-
}
129+
repositories {
130+
mavenLocal()
131+
mavenCentral()
132+
}
133+
134+
apply plugin: 'java'
135+
apply plugin: 'eclipse'
136+
apply plugin: 'idea'
137+
apply plugin: 'com.newrelic.gradle-verify-instrumentation-plugin'
138+
139+
java {
140+
toolchain {
141+
languageVersion = JavaLanguageVersion.of(8)
142+
}
143+
}
144+
145+
dependencies {
146+
testImplementation fileTree(dir: '../lib', include: "*.jar") // + project.javaAgentVersion
147+
testImplementation 'org.nanohttpd:nanohttpd:2.3.1'
148+
testImplementation 'com.newrelic.agent.java:newrelic-agent:' + project.javaAgentVersion
149+
}
150+
151+
tasks.register('install', Copy) {
152+
description = 'Copies compiled jar to the NEW_RELIC_EXTENSIONS_DIR.'
153+
group = 'New Relic Labs'
154+
155+
def extDir = System.getenv("NEW_RELIC_EXTENSIONS_DIR") ?: " "
156+
157+
from jar
158+
into extDir
159+
}
160+
161+
install.doFirst {
162+
def extDir = System.getenv("NEW_RELIC_EXTENSIONS_DIR")
163+
if (extDir == null) {
164+
throw new Exception("Must set NEW_RELIC_EXTENSIONS_DIR.")
165+
}
166+
167+
if (extDir.startsWith("~" + File.separator)) {
168+
extDir = System.getProperty("user.home") + extDir.substring(1);
169+
}
170+
171+
if (!file(extDir).directory) {
172+
throw new Exception(extDir + "NEW_RELIC_EXTENSIONS_DIR, set as '" + extDir + "'is not a valid directory.")
173+
}
174+
}
204175
}

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
java.agent.version=8.6.0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)