[Maven] Using another plugin as a dependency for it's API

Discussion in 'Plugin Development' started by skipperguy12, Jun 26, 2013.

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

    skipperguy12

    Hello, I'm trying to use Tracker by Overcast (https://github.com/OvercastNetwork/Tracker) with Maven, and I got it to work by using my friends Maven repository.

    The problem is, Maven automatically goes ahead and compile their entire plugin into my final Jar, and their plugin also has an onEnable() and everything required for it to be a plugin, so when I try to run my plugin, their onEnable overpowers mine and my plugin loads up Tracker, rather than my plugin.

    How do I stop it from compiling into my plugin? Tracker is already in my /plugins/ folder, I tried changing the dep scope to runtime, and provided, but it still goes ahead and packages their code into my jar. Here is parts of my pom.xml:

    Deps and reps:
    Code:
     <dependencies>
            <dependency>
                <groupId>tc.oc</groupId>
                <artifactId>tracker</artifactId>
                <version>0.1.0-SNAPSHOT</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
       
        <repositories>
            <repository>
                <id>molenzwiebel-snapshots</id>
                <url>https://github.com/molenzwiebel/MvnRepo/raw/master/snapshots</url>
            </repository>
        </repositories>
    Build:
    Code:
    <build>
            <sourceDirectory>${basedir}/src/main/java/</sourceDirectory>
            <resources>
                <resource>
                    <targetPath>.</targetPath>
                    <filtering>true</filtering>
                    <directory>${basedir}/src/main/resources/</directory>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
     
  2. Offline

    LucasEmanuel

    use "provided" as scope for the dependency instead of "runtime" :)
     
  3. Offline

    skipperguy12

    Hey LucasEmanuel , thanks for the reply! Sadly, it didn't work, I tried using this:
    Code:
            <dependency>
                <groupId>tc.oc</groupId>
                <artifactId>tracker</artifactId>
                <version>0.1.0-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
    But JD-GUI shows the packages of the plugin, their still in there! :(
    Any idea why this could be? Did I configure my build settings wrong?
     
  4. Offline

    Comphenix

    Perhaps you could post your entire pom.xml file?
     
  5. Offline

    skipperguy12

    Hello Comphenix , here is the full pom.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <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>
        <!-- Project information -->
        <groupId>com.github.skipperguy12</groupId>
        <artifactId>Database</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <description>Database plugin for Explosive Network</description>
        <dependencies>
            <dependency>
                <groupId>com.sk89q</groupId>
                <artifactId>command-framework-bukkit</artifactId>
                <version>0.4-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>tc.oc</groupId>
                <artifactId>sportbukkit-api</artifactId>
                <version>1.5.2-R0.2-SNAPSHOT</version>
            </dependency>
            <dependency>
                <groupId>tc.oc</groupId>
                <artifactId>tracker</artifactId>
                <version>0.1.0-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
       
        <repositories>
            <repository>
                <id>overcast-repo</id>
                <name>Overcast Network repo</name>
                <url>http://repo.oc.tc/content/groups/public/</url>
            </repository>
            <repository>
                <id>molenzwiebel-snapshots</id>
                <url>https://github.com/molenzwiebel/MvnRepo/raw/master/snapshots</url>
            </repository>
        </repositories>
       
       
       
        <build>
            <sourceDirectory>${basedir}/src/main/java/</sourceDirectory>
            <resources>
                <resource>
                    <targetPath>.</targetPath>
                    <filtering>true</filtering>
                    <directory>${basedir}/src/main/resources/</directory>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
        <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        </properties>
    </project>
    Some extra info (probably doesn't matter, but I'll go ahead anyways):
    • I run an Ubuntu 64 bit
    • I run Eclipse version 3.7.2 build id: I20110613-1736
    • I am using m2e - Maven Integration for Eclipse plugin
    • I am using Apache Maven 2.2.1 (rdebian-8)
    • I use Java version 1.7.0_25
    If there is any more info I need to give, please ask.
     
  6. Offline

    Comphenix

    Hm, could you try cleaning before building. That can be accomplished by clicking Project -> Clean, or executing mvn clean package.
     
  7. Offline

    Wingzzz

    Try compiling what you're depending on and mvn install it. Then depend on that artifact. I find this odd as I was under the impression you would only receive an "uber-jar" via shading.
     
  8. Offline

    skipperguy12

    Comphenix Wingzzz
    Hello! I got it to work by using clean. But now, I have another problem (this day just keeps getting worse and worse...):
    The other dependency no longer gets compiled into the jar. I tried adding a compile scope to it, but that didn't do the trick. How can I compile the framework's classes into the final jar, but not the tracker?
     
  9. Offline

    Comphenix

    The proper method is the Maven Shade Plugin. What you've been doing to date is more of an unintended side-effect (lack of cleaning).

    Here's how I embed CGLib in ProtocolLib and rename its destination package, while also excluding CraftBukkit and JUnit from ending up in the JAR (which would be insane).
     
    Europia79 likes this.
Thread Status:
Not open for further replies.

Share This Page