Maven build jar with dependencies

Discussion in 'BungeeCord Plugin Development' started by RcExtract, Jul 22, 2018.

  1. I would like to build a jar of my plugin with the maven assembly plugin in order to also build with specific dependencies inside the output jar. But it does not seem to work, the output jar does not include the org.apache.opennlp.opennlp-tools dependency. Any ideas?

    pom.xml:
    Code (XML):
    <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.teampublic</groupId>
      <artifactId>nettitalks</artifactId>
      <version>Alpha 6.2</version>
      <packaging>jar</packaging>
      <name>NettiTalks</name>
      <description>Private.</description>
      <inceptionYear>2018</inceptionYear>
      <build>
      <pluginManagement>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
              <source>1.10</source>
              <target>1.10</target>
            </configuration>
          </plugin>
          <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>

                    </configuration>
                    <executions>
                      <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                      </execution>
                    </executions>
                </plugin>
          <plugin>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.8.2</version>
            <executions>
              <execution>
                <id>default-deploy</id>
                <phase>deploy</phase>
                <goals>
                  <goal>deploy</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-release-plugin</artifactId>
            <version>2.5.3</version>
            <configuration>
              <localCheckout>true</localCheckout>
              <pushChanges>false</pushChanges>
              <mavenExecutorId>forked-path</mavenExecutorId>
              <arguments>-Dgpg.passphrase=${gpg.passphrase}</arguments>
            </configuration>
            <dependencies>
              <dependency>
                <groupId>org.apache.maven.scm</groupId>
                <artifactId>maven-scm-provider-gitexe</artifactId>
                <version>1.10.0</version>
              </dependency>
            </dependencies>
          </plugin>
        </plugins>
        </pluginManagement>
      </build>
      <repositories>
        <repository>
            <id>bungeecord-repo</id>
            <name>Bungeecord</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
            <releases>
              <enabled>true</enabled>
              <updatePolicy>daily</updatePolicy>
              <checksumPolicy>fail</checksumPolicy>
            </releases>
        </repository>
      </repositories>
      <dependencies>
            <dependency>
                <groupId>net.md-5</groupId>
                <artifactId>bungeecord-api</artifactId>
                <version>1.12-SNAPSHOT</version>
                <type>jar</type>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>net.md-5</groupId>
                <artifactId>bungeecord-api</artifactId>
                <version>1.12-SNAPSHOT</version>
                <type>javadoc</type>
                <scope>provided</scope>
            </dependency>
        <dependency>
          <groupId>org.apache.opennlp</groupId>
          <artifactId>opennlp-tools</artifactId>
          <version>1.9.0</version>
          <type>jar</type>
        </dependency>
      </dependencies>
    </project>
     
  2. MiniDigger

    Supporter

    generally the maven shade plugin is preferred for uber jars as it provides more control.

    however your code seems correct. how do you execute the build?
     
  3. Try using <scope>compile</scope> inside <dependency>.
     
  4. mvn package. Default scope is compile, so not required.

    EDIT: I solved it by removing the moving the plugins element out of pluginManagement and remove pluginManagement.
     
    #4 RcExtract, Jul 23, 2018
    Last edited: Jul 23, 2018