How to define agent for a test run in Gradle and Maven (JEP 451 workaround) #1535
nineninesevenfour
started this conversation in
General
Replies: 1 comment 3 replies
-
The easiest approach I know is to specify |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is not a question, I rather want to share the result of my research.
Background
JEP 451 with JDK 21 is the first step to restrict dynamic loading of agents. Currently when calling
ByteBuddyAgent.install()
with JDK 21 one will recieve the following warings:-XX:+EnableDynamicAgentLoading
cannot be seen as a permanent solution as well. It is there for monitoring purposes. Dyamic loading of an agent from a jar already present on the class path will be prohibited in a future JDK version.So I wanted to know how to add
-javaagent
to a test run including downloading the dependency to the agent from the configured repositories. This is the result:(corrections and comments are of course welcome).
Gradle
The artifact
byte-buddy-agent
can be resolved with an auxiliary configuration itembyteBuddyAgent
+ usingconfigurations.byteBuddyAgent.singleFile
(the name of the configuration can be chosen according to personal taste, of course).--> 5 Lines added
Maven
Usage of
maven-dependency-plugin
to create a temporary copy beneath thetarget
directory. This avoids having to specify an absolute path (to the local repo). However the version must be repeated in-javaagent
, therefor I used an additionalbyte.buddy.version
property.--> 1 property + 2 plugin configurations added
Test Code
To test the actual presence of the ByteBuddy agent I used:
Conclusion
ByteBuddyAgent.install()
, because luckily it triesgetInstrumentation()
first and will therefor resolve (the instrumentation of) the previously configured Java agent and skip dynamic installation.Beta Was this translation helpful? Give feedback.
All reactions