Can't get Maven dependency plugin to package a dependency in the jar

Discussion in 'Plugin Development' started by Tecno_Wizard, Oct 14, 2016.

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

    Tecno_Wizard

    Kinda self-explanatory. I'm a Maven noob, so I apologize if this a dumb mistake. When I compile, I can't get the BukkitPluginUtils dependency to be extracted to the output jar. I have the maven dependency plugin installed, but I must have it misconfigured.

    pom
    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>
        <groupId>com.ethanzeigler.commandsforsale2</groupId>
        <artifactId>CommandsForSale2</artifactId>
        <version>1.0-SNAPSHOT</version>
        <repositories>
            <repository>
                <id>spigot-repo</id>
                <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
        </repositories>
        <dependencies>
            <dependency>
                <groupId>org.bukkit</groupId>
                <artifactId>bukkit</artifactId>
                <version>1.10.2-R0.1-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>com.ethanzeigler.bukkitpluginutils</groupId>
                <artifactId>BukkitPluginUtils</artifactId>
                <version>1.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.10</version>
                    <configuration>
                        <includeArtifactIds>BukkitPluginUtils</includeArtifactIds>
                    </configuration>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>unpack-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>unpack-dependencies</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
     
  2. Offline

    DoggyCode™

    You must use a maven dependency compiler plugin. I always go with

    Code:
    <build>
      <plugins>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <configuration>
            <archive>
              <manifest>
                <mainClass>fully.qualified.MainClass</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
          </configuration>
        </plugin>
      </plugins>
    </build>
    and you build the jar by performing this command in the terminal:
    mvn clean compile assembly:single

    EDIT:
    And also, why is this in the "Plugin Requests" subforum?
     
  3. Online

    timtower Administrator Administrator Moderator

    Moved to plugin development.
    @DoggyCode™ Please report it next time instead of commenting and asking about it.
     
  4. Offline

    DoggyCode™

    Sorry! :)
     
  5. Offline

    Tecno_Wizard

    Because I had an exam in a half an hour and my brain wasn't screwed on correctly. lol
    @timtower sorry about that.

    Thanks. I'll add this in with my packaging goals. I got sick of switching between computers for school and having all of my dependencies screwed up so I thought I'd try maven.
     
  6. Offline

    DoggyCode™

    Yeah. Maven can be very great and useful at most times, but not always, and can be tricky at times.

    Sent from my SM-N9005 using Tapatalk
     
  7. Offline

    Tecno_Wizard

    @DoggyCode™, tricky indeed because I've now spent 2 days on this issue:

    The assembly plugin refuses to download from central, and there's no good reason as to why because if I use the terminal instead of the IntelliJ GUI system, it works fine.
    Code:
    [ERROR] Plugin org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5 or one of its dependencies could not be resolved: The repository system is offline but the artifact org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-beta-5 is not available in the local repository. -> [Help 1]
    [ERROR]
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR]
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginResolutionException
     
    Last edited: Oct 16, 2016
  8. Offline

    mythbusterma

    @Tecno_Wizard

    You need to tell IntelliJ to download the repository manifest.
     
  9. Offline

    Tecno_Wizard

    @mythbusterma that didn't work, but I remembered the invalidate caches command. That did it. I guess something was wrong with the GUI synchronization in maven.

    Thanks for the help guys. I really hate not being able to find the answer myself, but sometimes it just isn't feasible.
     
    Last edited: Oct 17, 2016
Thread Status:
Not open for further replies.

Share This Page