java - maven- assembly-plugin 不打包依赖项

标签 java maven maven-assembly-plugin

我已经在其他项目中使用 maven-assemble-plugin 将依赖项打包到单个 jar 中,但是在我当前的项目中,没有创建具有依赖项的 jar,我很困惑为什么。在其他项目中,我会看到生成的两个 jar xxx-1.0-SNAPSHOT.jarxxx-1.0-SNAPSHOT-jar-with-dependency.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>

最佳答案

原因是,您仅在<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.

同时<plugins/>是插件的实际调用。它可能会也可能不会从 <pluginManagement/> 继承。 。因此它应该像 <build/> 中那样被调用。直接:

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

关于java - maven- assembly-plugin 不打包依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52443672/

相关文章:

java - 如何在android中从三个数字中获取特定的随机数

java - Jenkins 会吞下 MojoFailureException 吗?

java - 如何针对HDP 2.6.1.0堆栈构建应用程序

java - Maven过滤没有选择好的文件

java - 使用程序集插件进行 Maven 构建时出错

java - assembly-maven-plugin 不生成带有依赖项的 jar,并且没有主 list 属性

java - 某些 JVM 是否会缓存常用库类的静态初始化结果

java - SPNEGO 获取用户详细信息

java - 构建计步器时 onAccuracyChanged 方法有什么意义?

java - 如何使用 Maven 创建独立的应用程序且依赖关系完好无损?