maven-assembly-plugin不包装依赖项

时间:2018-09-21 12:21:37

标签: java maven maven-assembly-plugin

在其他项目中,我已经使用maven-assembly-plugin将依赖项打包到单个jar中,但是在我当前的项目中,没有创建具有依赖项的jar,我为之困惑。在其他项目中,我会看到两个jar分别生成了xxx-1.0-SNAPSHOT.jarxxx-1.0-SNAPSHOT-jar-with-dependencies.jar,但是在此项目中,仅生成了xxx-1.0-SNAPSHOT.jar文件。

这是我的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>

1 个答案:

答案 0 :(得分:1)

原因是,您仅在<pluginmanagement/>内定义了程序集插件。

  

pluginManagement是随侧面插件一起出现的元素。   插件管理包含插件元素的方式几乎相同,   除非为此配置插件信息   特定的项目构建,旨在配置项目构建   从这一继承。但是,这只会配置   实际上是在子级或子级的plugins元素内引用的   在当前POM中。孩子们有权行使一切权利   pluginManagement定义。

<plugins/>是插件的实际调用。它可能会或可能不会从<pluginManagement/>继承。因此,应直接在<build/>中调用它:

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