Solved Maven shading with mcstats

Discussion in 'Plugin Development' started by Alshain01, Nov 20, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Alshain01

  2. Offline

    Goblom

    Alshain01 I looks like when you tried using Maven-Shade-Plugin you broke a part of your pom. The problem is with the MCStats metrics, i believe is at around line 45 of pom.xml

    It would be easier to just download the MCStats Metrics source and put it in the io.github.alshain01.Flags.metrics package.

    Link to Metrics Bukkit source ---> Metrics Lite or Metrics Normal
    Edit: Just realized you may be getting that error because the Metrics class you are relocating might not have its package get changed so java doesn't know where it is.
     
  3. Offline

    Alshain01

    Sorry but none of that really helps me much. I know this is possible, it was designed to do this and many plugins use it this way.
     
  4. Offline

    desht

    Alshain01 I've done this successully with my plugins. As an example take a look at https://github.com/desht/autohop/blob/master/pom.xml

    Looking at the difference between your POM and mine, I'm using metrics-lite rather than metrics, and I use an older version of the shader plugin here (but I don't think either of those are significant), and I don't have that artifactSet definition that you use (I use minimizeJar). I also notice that your shaded package (io.github.alshain01.Flags.metrics) for the MCstats class is the same as the package name for your own MetricsManager class. Perhaps try a separate package for the shaded library.
     
  5. Offline

    Alshain01

    Thanks desht,

    I changed it to be almost identical to yours and still no luck. The moment the scheduler hits to start metrics (which is right after it finishes loading everything) it gives me the same error.

    Code:
    2013-11-21 07:01:49 [WARNING] [Flags] Task #14 for Flags v1.3.0 generated an exception
    java.lang.NoClassDefFoundError: org/mcstats/Metrics$Plotter
        at io.github.alshain01.Flags.Flags$onServerEnabledTask.run(Flags.java:98)
        at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:53)
        at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
        at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:524)
        at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
        at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
        at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
        at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.ClassNotFoundException: org.mcstats.Metrics$Plotter
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at org.bukkit.plugin.java.PluginClassLoader.findClass0(PluginClassLoader.java:80)
        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:53)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 8 more
     
  6. Offline

    desht

    Odd. Your POM looks OK to me. Can you upload the JAR somewhere so I can have a closer look?
     
  7. Offline

    Europia79

    Alshain01 desht
    Did you guys solve this issue ?
    If so, I curious what you did.
     
  8. Offline

    Alshain01

    Yes and no, that was back when I was learning Maven and didn't realize compiling with eclipse wasn't the same as compiling with Maven. Since then desht talked me into IntelliJ and I'm never ever going back. That solved the the Maven problems, but as for shading, that concept still eludes me. I technically got it to work but it compiled so much crap into my plugin, I decided it wasn't worth it.
     
  9. Offline

    desht

    If shading is pulling a load of unwanted classes in, you've probably declared the wrong scope for the dependency in question. Use a scope of "provided" for any dependency that will be provided at runtime, e.g. Bukkit itself, or another plugin you're depending upon. Use a scope of "compile" (the default) if you want to include the dependency in your JAR.
     
    Europia79 likes this.
  10. Offline

    Alshain01

    Ah, well I'll keep that in mind but I also decided I don't like "universal disable" options. There is no reason my plugin should be punished because some other plugin is sending gobs of data or using an outdated version of metrics that is throwing tons of console errors. *ahem* Multiverse-Core, I'm looking at you. So now I tweak the metrics code so it ignores opt-out and put the option in my config.yml. I can't do that with Maven anyways.
     
  11. Offline

    Europia79


    Dude, thank you so much... This solved my issue. Also, before posting, i combed thru tons of documentation, articles, and tutorials that did not mention this caveat about the maven-shade-plugin.
     
Thread Status:
Not open for further replies.

Share This Page