Search code examples
mavenaopaspectjmaven-shade-pluginkamon

Kamon AspecJWeaver dependency not working with allinone jar


I'm using Kamon with akka 2.4 (remote included).

This means that I need to include a -javaagent option to launch as specified by the Kamon doc.

The issue is that my Maven is building an allinone jar:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>allinone</shadedClassifierName>
                        <artifactSet>
                            <includes>
                                <include>*:*</include>
                            </includes>
                        </artifactSet>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>reference.conf</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <main-Class>my.main.Program</main-Class>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

If I run things from within the IDE (Intellij), it works fine by adding either:

-javaagent:full\path\to\aspectjweaver-1.8.10.jar

or these 2 to the pom:

    <dependency>
        <groupId>io.kamon</groupId>
        <artifactId>kamon-autoweave_2.11</artifactId>
        <version>0.6.5</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.8.10</version>
    </dependency>

The problem is that once I actually build the jar (mvn clean package), and I run it with (or without) the -javaagent option (java -javaagent... -jar app.jar) , the weaving does not happen, and no metric are reported when running outside the IDE.

I find it hard to debug the issue because even with

kamon.metric.disable-aspectj-weaver-missing-error = false

Kamon does not tell me that weaving is missing.

I believe this to be due to Java not finding the Weaver classes in the path, but I'm at my wit's end.

Any help? The goal is to run the jar externally with weaving


Solution

  • Found the answer in an old user group post here:

    You need to add

    <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
        <resource>META-INF/aop.xml</resource>
    </transformer>
    

    To your transformers.