ryandens / javaagent-gradle-plugin

A set of Gradle plugins to ease building Java applications that leverage instrumentation agents in development and/or in production
Apache License 2.0
47 stars 8 forks source link

The plugin doesn't work with the gradle shadow plugin #100

Closed swamyrajamohan closed 4 months ago

swamyrajamohan commented 5 months ago

When used with the gradle-shadow plugin and creating the shadowDistTar or shadowDistZip instead of the regular distZip and distTar provided by the application plugin the resultant distributions don't contain the agent-libs directory in the distribution (zip/tar).

tar produced by the distTar after applying the javaagent-gradle-plugin agent-libs # containing the javaagent lib bin # containing the startup scripts lib # containing the dependent libraries and application jar

tar produced by the distTar after applying the javaagent-gradle-plugin

Misses the agent-libs folder containing javaagent lib

bin # containing the startup scripts lib # containing the dependent libraries and application jar


plugins {
    id 'java'
    id 'groovy'
    id 'application'
    id 'com.ryandens.javaagent-application' version '0.4.2'  
    id 'maven-publish'
    id 'com.github.jk1.dependency-license-report' version '2.5'
    id 'com.github.johnrengelman.shadow' version '8.1.1'
    id 'org.sonarqube' version '4.4.1.3373'
    id 'org.owasp.dependencycheck' version '9.0.9'
}
swamyrajamohan commented 5 months ago

Tried it with the newer version 0.5.1 as well and still the same issue

ryandens commented 5 months ago

👋 i wouldn't expect it to work with the artifacts built by the shadow task - feel free to make a PR! If you want to make a specific proposal around any api changes, let me know. I'm unfamiliar with the purpose of the shadowDistTar and shadowDistZip tasks? My understanding was the purpose of the shadow plugin was to create an uber-jar that could be run in a standalone fashion. What is the purpose of putting an uber-jar inside of a tar/zip that uses a start script and abstracts away adding dependencies to the classpath? Adding support for a new plugin integration creates a maintenance burden, so I would need to see a compelling reason for folks to actually use a javaagent with these distributions.

Note that javaagents themselves can't be shaded into the shadow jar, as they need to be specified with the -javaagent flag or registered programatically. Perhaps you're looking for something like https://github.com/open-telemetry/opentelemetry-java-contrib/tree/main/static-instrumenter

tajobe commented 4 months ago

I think this is the same as #94, where I've included a potential workaround @swamyrajamohan

ryandens commented 4 months ago

closed as duplicate of #94