Skip to content

Commit 505711a

Browse files
authored
Publish runtime-attach artifact (#2341)
* Publish runtime-attach artifact * Fix
1 parent ff783f7 commit 505711a

File tree

5 files changed

+103
-73
lines changed

5 files changed

+103
-73
lines changed

agent/agent/build.gradle.kts

Lines changed: 30 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,18 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
33
plugins {
44
id("ai.java-conventions")
55
id("ai.shadow-conventions")
6-
id("maven-publish")
6+
id("ai.publish-conventions")
77
}
88

99
base.archivesName.set("applicationinsights-agent")
1010

11-
java {
12-
withJavadocJar()
13-
withSourcesJar()
14-
}
15-
1611
// this configuration collects libs that will be placed in the bootstrap classloader
17-
val bootstrapLibs: Configuration by configurations.creating {
12+
val bootstrapLibs by configurations.creating {
1813
isCanBeResolved = true
1914
isCanBeConsumed = false
2015
}
2116
// this configuration collects libs that will be placed in the agent classloader, isolated from the instrumented application code
22-
val javaagentLibs: Configuration by configurations.creating {
17+
val javaagentLibs by configurations.creating {
2318
isCanBeResolved = true
2419
isCanBeConsumed = false
2520
}
@@ -57,10 +52,6 @@ project(":agent:instrumentation").subprojects {
5752
}
5853

5954
tasks {
60-
jar {
61-
enabled = false
62-
}
63-
6455
// building the final javaagent jar is done in 3 steps:
6556

6657
// 1. all distro-specific javaagent libs are relocated (by the ai.shadow-conventions plugin)
@@ -103,79 +94,46 @@ tasks {
10394
dependsOn(isolateJavaagentLibs)
10495
from(isolateJavaagentLibs.get().outputs)
10596

106-
archiveClassifier.set("all")
107-
10897
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
10998

99+
archiveClassifier.set("")
100+
110101
manifest {
102+
attributes(jar.get().manifest.attributes)
111103
attributes(
112-
mapOf(
113-
"Premain-Class" to "com.microsoft.applicationinsights.agent.Agent",
114-
// Agent-Class is provided only for dynamic attach in the first line of main
115-
// there are many problematic edge cases around dynamic attach any later than that
116-
"Agent-Class" to "com.microsoft.applicationinsights.agent.Agent",
117-
"Can-Redefine-Classes" to true,
118-
"Can-Retransform-Classes" to true
119-
)
104+
"Agent-Class" to "com.microsoft.applicationinsights.agent.Agent",
105+
"Premain-Class" to "com.microsoft.applicationinsights.agent.Agent",
106+
"Can-Redefine-Classes" to true,
107+
"Can-Retransform-Classes" to true
120108
)
121109
}
122110
}
123111

124-
// a separate task to create a no-classifier jar that's exactly the same as the -all one
125-
// because a no-classifier (main) jar is required by sonatype
126-
val mainShadowJar by registering(Jar::class) {
127-
archiveClassifier.set("")
128-
129-
from(zipTree(shadowJar.get().archiveFile))
130-
131-
manifest {
132-
attributes(shadowJar.get().manifest.attributes)
133-
}
112+
jar {
113+
// Empty jar that cannot be used for anything and isn't published.
114+
archiveClassifier.set("dontuse")
134115
}
135116

136117
assemble {
137-
dependsOn(shadowJar, mainShadowJar)
118+
dependsOn(shadowJar)
138119
}
139120

140-
val t = this
141-
publishing {
142-
publications {
143-
register<MavenPublication>("maven") {
144-
artifactId = "applicationinsights-agent"
145-
groupId = "com.microsoft.azure"
146-
version = project.version.toString()
147-
148-
artifact(shadowJar)
149-
artifact(mainShadowJar)
150-
artifact(t.named("sourcesJar"))
151-
artifact(t.named("javadocJar"))
152-
153-
pom {
154-
name.set("Microsoft Application Insights Java Agent")
155-
description.set("Microsoft Application Insights Java Agent")
156-
url.set("https://github.com/Microsoft/ApplicationInsights-Java")
157-
packaging = "jar"
158-
159-
licenses {
160-
license {
161-
name.set("MIT License")
162-
url.set("http://www.opensource.org/licenses/mit-license.php")
163-
}
164-
}
165-
166-
developers {
167-
developer {
168-
id.set("Microsoft")
169-
name.set("Microsoft")
170-
}
171-
}
172-
173-
scm {
174-
connection.set("scm:git:git://github.com/Microsoft/ApplicationInsights-Java.git")
175-
url.set("scm:git:https://github.com/Microsoft/ApplicationInsights-Java")
176-
}
177-
}
178-
}
121+
// Because we reconfigure publishing to only include the shadow jar, the Gradle metadata is not correct.
122+
// Since we are fully bundled and have no dependencies, Gradle metadata wouldn't provide any advantage over
123+
// the POM anyways so in practice we shouldn't be losing anything.
124+
withType<GenerateModuleMetadata>().configureEach {
125+
enabled = false
126+
}
127+
}
128+
129+
// Don't publish non-shadowed jar (shadowJar is in shadowRuntimeElements)
130+
with(components["java"] as AdhocComponentWithVariants) {
131+
configurations.forEach {
132+
withVariantsFromConfiguration(configurations["apiElements"]) {
133+
skip()
134+
}
135+
withVariantsFromConfiguration(configurations["runtimeElements"]) {
136+
skip()
179137
}
180138
}
181139
}

agent/runtime-attach/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
plugins {
22
id("ai.java-conventions")
3+
id("ai.publish-conventions")
34
}
45

6+
base.archivesName.set("applicationinsights-runtime-attach")
7+
58
val otelContribAlphaVersion: String by project
69
val otelVersion: String by project
710

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# This is a Gradle generated file for dependency locking.
2+
# Manual edits can break the build and are not advised.
3+
# This file is expected to be part of source control.
4+
com.azure:azure-sdk-bom:1.2.2=runtimeClasspath
5+
com.google.guava:guava-bom:31.1-jre=runtimeClasspath
6+
io.opentelemetry.contrib:opentelemetry-runtime-attach:1.15.0-alpha=runtimeClasspath
7+
io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:1.15.0-alpha=runtimeClasspath
8+
io.opentelemetry:opentelemetry-bom-alpha:1.15.0-alpha=runtimeClasspath
9+
io.opentelemetry:opentelemetry-bom:1.15.0=runtimeClasspath
10+
net.bytebuddy:byte-buddy-agent:1.12.9=runtimeClasspath
11+
org.junit:junit-bom:5.8.2=runtimeClasspath
12+
empty=
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
plugins {
2+
`maven-publish`
3+
signing
4+
}
5+
6+
publishing {
7+
publications {
8+
register<MavenPublication>("maven") {
9+
plugins.withId("java-platform") {
10+
from(components["javaPlatform"])
11+
}
12+
plugins.withId("java-library") {
13+
from(components["java"])
14+
}
15+
16+
versionMapping {
17+
allVariants {
18+
fromResolutionResult()
19+
}
20+
}
21+
22+
afterEvaluate {
23+
groupId = "com.microsoft.azure"
24+
artifactId = base.archivesName.get()
25+
26+
pom.description.set(
27+
project.description
28+
?: "Microsoft Application Insights Java Agent."
29+
)
30+
}
31+
32+
pom {
33+
name.set("Microsoft Application Insights Java Agent")
34+
url.set("https://github.com/Microsoft/ApplicationInsights-Java")
35+
36+
licenses {
37+
license {
38+
name.set("MIT License")
39+
url.set("http://www.opensource.org/licenses/mit-license.php")
40+
}
41+
}
42+
43+
developers {
44+
developer {
45+
id.set("Microsoft")
46+
name.set("Microsoft")
47+
}
48+
}
49+
50+
scm {
51+
connection.set("scm:git:git://github.com/Microsoft/ApplicationInsights-Java.git")
52+
url.set("scm:git:https://github.com/Microsoft/ApplicationInsights-Java")
53+
}
54+
}
55+
}
56+
}
57+
}

smoke-tests/servers/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ext {
88
globalResourcesDir = "$projectDir/global-resources"
99
agentLibsDir = file("${project(':agent:agent').buildDir}/libs")
1010
// is there a better way to get this?
11-
agentJarName = project(":agent:agent").jar.archiveFileName.get()
11+
agentJarName = project(":agent:agent").shadowJar.archiveFileName.get()
1212
}
1313

1414
subprojects {

0 commit comments

Comments
 (0)