Skip to content

Commit

Permalink
Attaching bytebuddy plugins using the ByteBuddyDependencyAttacher
Browse files Browse the repository at this point in the history
  • Loading branch information
LikeTheSalad committed Feb 12, 2025
1 parent 6c004cd commit 902fd94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package co.elastic.otel.android.plugin.internal

import org.gradle.api.Project

class ByteBuddyDependencyAttacher(
private val project: Project,
private val dependencyUri: String
) : BuildVariantListener {

override fun onBuildVariant(name: String) {
project.configurations.maybeCreate("${name}ByteBuddy").dependencies.add(
project.dependencies.create(dependencyUri)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import org.junit.Before
import org.junit.Rule
import org.junit.Test


class InstrumentationTest {

@get:Rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package co.elastic.otel.android.okhttp

import co.elastic.otel.android.instrumentation.generated.BuildConfig
import co.elastic.otel.android.plugin.ElasticAgentPlugin
import co.elastic.otel.android.plugin.internal.ByteBuddyDependencyAttacher
import co.elastic.otel.android.plugin.internal.InstrumentationPlugin
import org.gradle.api.Project

Expand All @@ -12,9 +13,11 @@ class OkHttpInstrumentationPlugin : InstrumentationPlugin() {
"implementation",
target.dependencies.create(BuildConfig.LIBRARY_URI)
)
target.dependencies.add(
"byteBuddy",
target.dependencies.create(BuildConfig.BYTEBUDDY_PLUGIN)
agentPlugin.addBuildVariantListener(
ByteBuddyDependencyAttacher(
target,
BuildConfig.BYTEBUDDY_PLUGIN
)
)
}
}

0 comments on commit 902fd94

Please sign in to comment.