Solved Problems with Maven and DHUtils

Discussion in 'Plugin Development' started by LucasEmanuel, Jun 4, 2013.

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

    LucasEmanuel

    I started looking into Maven today for the first time to be able to work with DHUtils in one of my plugins, so I'm a total Maven noob. But it seems I have yet to understand how to add DHUtils as a dependency.

    I can compile plugins just fine that are not working against DHUtils. But when I try to compile plugins that are working against the DHUtils-lib Maven seems to skip all classes that are not directly referenced in my code. I assume there is something that I have missed, but when I compare my pom.xml file against desht in his ChessCraft there don't seem to be any differences that would impact the shading. So I'm guessing something might be wrong with my code.

    I have tried to replicate the way desht uses the MBU in ChessCraft, but I must be overseeing something.

    I hope someone of you guys can help me out with this :)

    My pom.xml:
    Code:
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>me.lucasemanuel</groupId>
      <artifactId>survivalgamesmultiverse</artifactId>
      <version>0.9.5</version>
      <name>SurvivalGamesMultiverse</name>
     
      <!-- Repositories -->
      <repositories>
            <repository>
                <id>bukkit-repo</id>
                <url>http://repo.bukkit.org/content/groups/public</url>
            </repository>
        </repositories>
       
     
      <!-- Dependencies -->
      <dependencies>
     
          <!-- Bukkit -->
          <dependency>
              <groupId>org.bukkit</groupId>
              <artifactId>craftbukkit</artifactId>
              <version>1.5.2-R0.2-SNAPSHOT</version>
              <scope>provided</scope>
          </dependency>
         
          <!-- DHUtils -->
          <dependency>
                <groupId>me.desht</groupId>
                <artifactId>dhutils-lib</artifactId>
                <version>2.5.2</version>
          </dependency>
      </dependencies>
     
     
      <build>
            <finalName>${project.name}</finalName>
            <defaultGoal>clean package</defaultGoal>
     
            <!-- Resources -->
            <resources>
                <resource>
                    <targetPath>.</targetPath>
                    <directory>${basedir}/src/main/resources/</directory>
                    <filtering>true</filtering>
                    <includes>
                        <include>*.yml</include>
                        <include>*.dat</include>
                    </includes>
                </resource>
            </resources>
     
            <!-- Plugins -->
            <plugins>
                <!-- Compiler -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.4</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                        <showDeprecation>true</showDeprecation>
                    </configuration>
                </plugin>
               
                <!-- Shader -->
                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <minimizeJar>false</minimizeJar>
                            <relocations>
                                <relocation>
                                    <pattern>me.desht.dhutils</pattern>
                                    <shadedPattern>me.lucasemanuel.survivalgamesmultiverse.dhutils</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            </plugins>
        </build>
    </project>
    My references to DHUtils:
    Code:
    public void onEnable() {
       
        logger = new ConsoleLogger(this, "Main");
        logger.debug("Initiating startup sequence...");
       
        logger.info("Checking compatability...");
       
        try {
            NMSHelper.init(this);
        }
        catch(Exception e) {
            logger.severe("Unsupported server version! Disabling plugin.");
            this.setEnabled(false);
            return;
        }
    .....
    Code:
    MassBlockUpdate mbu = CraftMassBlockUpdate.createMassBlockUpdater(plugin, world);
     
    for (LoggedBlock block : blocks_to_reset.values()) {
        block.reset(mbu);
    }
     
    mbu.notifyClients();
    
    Nevermind, I fixed it by adding the following filter :)
    Code:
    <filter>
        <artifact>me.desht:dhutils-lib</artifact>
        <includes>
            <include>me/desht/dhutils/nms/**</include>
            <include>me/desht/dhutils/block/**</include>
        </includes>
    </filter>
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    desht

    Glad you got it working. The includes/excludes gets a little screwy once you start messing around with reflection (which I do to work properly with multiple NMS versions - Maven's shading won't auto-pull in classes which are referenced indirectly via reflection. I've been thinking about shifting the NMS abstraction stuff out of dhutils-lib and into its own library, just for tidiness...

    Just for extra reference, this question describes the problem quite well: http://stackoverflow.com/questions/8817257/minimize-an-uber-jar-correctly-using-shade-plugin

    JAR minimisation doesn't work properly for class referred to by reflection - hence the need for explicit include statements and Maven 1.6. Unfortunately using even one include statement means all reference classes then need to be explicitly included. For ChessCraft I'm just including everything from dhutils-lib which is just plain lazy of me and something I need to fix :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
    LucasEmanuel likes this.
  3. Offline

    LucasEmanuel

    Yea, it's quite understandable that Maven won't pick up on what is referenced by reflection since it might be quite hard to foresee the dynamic references in reflection that don't happen until runtime.
     
Thread Status:
Not open for further replies.

Share This Page