Search code examples
javamavenmaven-assembly-plugin

maven-assembly-plugin not packaging dependencies


I've used maven-assembly-plugin to package dependencies into a single jar in other projects, however in my current project the jar with dependencies is not being created and I'm stumped as to why. In other projects I will see two jar's generated xxx-1.0-SNAPSHOT.jar and xxx-1.0-SNAPSHOT-jar-with-dependencies.jar, but in this project just the xxx-1.0-SNAPSHOT.jar file is being generated.

Here's my pom.xml

<?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>org.sk</groupId>
  <artifactId>gt_tutorial</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>gt_tutorial</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <geotools.version>20-RC</geotools.version>
    <jts.version>1.16.0-RC1</jts.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt-shapefile</artifactId>
      <version>${geotools.version}</version>
    </dependency>

    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt-swing</artifactId>
      <version>${geotools.version}</version>
    </dependency>

    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt-grid</artifactId>
      <version>${geotools.version}</version>
    </dependency>

    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt-epsg-hsql</artifactId>
      <version>${geotools.version}</version>
    </dependency>

    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt-geometry</artifactId>
      <version>${geotools.version}</version>
    </dependency>

    <dependency>
      <groupId>org.geotools</groupId>
      <artifactId>gt-geojson</artifactId>
      <version>${geotools.version}</version>
    </dependency>

    <dependency>
      <groupId>org.locationtech.jts</groupId>
      <artifactId>jts-core</artifactId>
      <version>${jts.version}</version>
    </dependency>

    <!-- JSR-363 support as recommended for GeoTools 20 http://docs.geotools.org/latest/userguide/welcome/upgrade.html -->
    <dependency>
      <groupId>systems.uom</groupId>
      <artifactId>systems-common-java8</artifactId>
      <version>0.7.2</version>
    </dependency>

  </dependencies>

  <repositories>
    <repository>
      <id>maven2-repository.dev.java.net</id>
      <name>Java.net repository</name>
      <url>http://download.java.net/maven/2</url>
    </repository>
    <repository>
      <id>osgeo</id>
      <name>Open Source Geospatial Foundation Repository</name>
      <url>http://download.osgeo.org/webdav/geotools/</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>boundless</id>
      <name>Boundless Maven Repository</name>
      <url>http://repo.boundlessgeo.com/main</url>
    </repository>
  </repositories>

  <build>
    <pluginManagement>
      <plugins>

        <plugin>
          <inherited>true</inherited>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.2</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
          </configuration>
        </plugin>

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-assembly-plugin</artifactId>
          <executions>
            <execution>
              <phase>package</phase>
              <goals>
                <goal>single</goal>
              </goals>
              <configuration>
                <archive>
                  <manifest>
                    <mainClass>
                      org.sk.Grid4
                    </mainClass>
                  </manifest>
                </archive>
                <descriptorRefs>
                  <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
              </configuration>
            </execution>
          </executions>
        </plugin>



      </plugins>
    </pluginManagement>
  </build>
</project>

Solution

  • Reason is, you have defined assembly plugin only within <pluginmanagement/>.

    pluginManagement is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one. However, this only configures plugins that are actually referenced within the plugins element in the children or in the current POM. The children have every right to override pluginManagement definitions.

    While <plugins/> is an actual invocation of the plugin. It may or may not be inherited from a <pluginManagement/>. Hence it should be called like within <build/> directly:

    <build>
       <plugins>
           <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-assembly-plugin</artifactId>
          <executions>
                  .....
          </execution>
          </plugin>
        </plugins>
      </build>