Solved How do I Maven Shade into my Maven Project?

Discussion in 'Spigot Plugin Development' started by Kingdomity, May 17, 2018.

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

    Kingdomity Previously TheSpyguy16

    Hello, Spigot Members!

    I know their is maven and utils APIs out there, but some have it were users have to download their API plugin to their server for the features to work in your plugin. My question is that is there a way to not do that. Because I have actionbar and titlebar feature in one of my plugins, but people or server owners need that plugin for them to work. I do know I can make the code for a ActionBar and TitleBar, but I tried and does not work.

    I don't want server owner's or users to not do a extra step just to get a extra feature to work!
     
    #1 Kingdomity, May 17, 2018
    Last edited: May 17, 2018
    • Informative Informative x 1
    • Informative Informative x 1
  2. Kingdomity

    Kingdomity Previously TheSpyguy16

    Some people don't like the newer versions due to combat changes and that's why they stay on 1.8. Therefore, for this reason that's why I support 1.8 and up.
     
  3. Yes I understand all the combat changes, but 1.8.8 development is a pain in the ass imo. But we all do it anyway xD
     
    • Agree Agree x 1
    • Informative Informative x 1
    • Useful Useful x 1
  4. Kingdomity

    Kingdomity Previously TheSpyguy16

    So how do I maven shade? For example shade this plugin (TTA) into my maven project.
     
  5. Don't shade it in. You don't know what plugins a server might be running as well as yours. They may have other plugins that depend on the API plugins you are shading and it will just cause conflicts.
    Use plugin.yml to set the API plugin as a dependency, and let the server admin add it to the server as necessary.
    Any decent server admin won't mind the extra step.
     
  6. You need to set the dependency’s scope to compile and add the maven shade plugin under the build section in your pom.xml. The examples provided are the bare minimum required and does not cover relocation of classes, the only changes required is to substitute guava’s dependency information with TTA’s which can be found on it’s plugin page.

    There’s always the option to relocate the classes/packages which would prevent conflicting dependencies.
     
    • Informative Informative x 1
  7. Kingdomity

    Kingdomity Previously TheSpyguy16

    This is what I tried and it does not work.

    Code (Text):
    <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>org.thespyguy16.main</groupId>
      <artifactId>Maven_Test</artifactId>
      <name>Maven_Test</name>
      <version>1.2.0</version>
                 
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      </properties>
       
      <repositories>
          <repository>
            <id>spigot-repo</id>
            <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
        </repository>
     
          <repository>
            <id>tta-repo</id>
            <url>http://releases.herbystar.eu/</url>
          </repository>
      </repositories>
     
     
      <dependencies>
        <!-- TTA API -->
        <dependency>
            <groupId>de.Herbystar</groupId>
            <artifactId>TTA</artifactId>
            <version>3.9</version>
            <scope>compile</scope>
        </dependency>
     
        <!-- Spigot API -->
        <dependency>
            <groupId>org.spigotmc</groupId>
            <artifactId>spigot-api</artifactId>
            <version>1.12.2-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>

        <!-- Bukkit API -->
        <dependency>
            <groupId>org.bukkit</groupId>
            <artifactId>bukkit</artifactId>
            <version>1.12.2-R0.1-SNAPSHOT</version>
            <scope>provided</scope>
        </dependency>
      </dependencies>
     
    <build>
            <resources>
                <resource>
                    <directory>${basedir}/src/main/resources</directory>
                    <filtering>true</filtering>
                    <includes>
                        <include>*</include>
                    </includes>
                </resource>
            </resources>
            <sourceDirectory>src/main/java</sourceDirectory>
         
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.1.1</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                             <configuration>
                                <artifactSet>
                                    <includes>
                                        <include>de.Herbystar:*</include>
                                    </includes>
                                </artifactSet>
                              </configuration>
                        </execution>
                    </executions>

                    <configuration>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>shaded</shadedClassifierName>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
     
  8. Here's a snippet from one of my poms:
    Code (Text):

    <!-- Shade all Libs -->
    <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.1.1</version>
            <executions>
                    <execution>
                            <phase>package</phase>
                            <goals>
                                    <goal>shade</goal>
                            </goals>
                            <configuration>
                                    <minimizeJar>true</minimizeJar>
                                    <createDependencyReducedPom>false</createDependencyReducedPom>
                                    <artifactSet>
                                            <includes>
                                                    <include>org.slf4j:*</include>
                                                    <include>com.zaxxer:*</include>
                                                    <include>org.javassist:javassist</include>
                                            </includes>
                                    </artifactSet>
                            </configuration>
                    </execution>
            </executions>
    </plugin>
     
     
    • Informative Informative x 1
Thread Status:
Not open for further replies.

Share This Page