java - mvn process-resources 不会拉下使用阴影插件创建的 uber jar

标签 java maven maven-3 executable-jar maven-shade-plugin

目标:使用 Maven Shade 插件创建一个可执行的 uber jar,可以在另一个 pom 的 mvn 编译期间执行。

重现步骤:

  1. 使用下面的 pom 为“publisher”组件创建 pom.xml。
  2. 使用 Jenkins 构建来 mvn 部署它(mvn install 也可以工作)
  3. 向 pom.xml 添加“consumer”的依赖项(下面的 pom)
  4. mvn 编译消费者

预期行为: 发布者的 Uber jar 已下载到消费者/目标目录中的某个位置

实际: Uber jar 没有出现在消费者目录中

组件 1:发布商

<?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.mec.experiment</groupId>
<artifactId>publisher</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.6.Final</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>src/main/resources/META-INF/MANIFEST.mf</manifestFile>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

组件 2:消费者

<?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.mec.experiment</groupId>
<artifactId>consumer</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>com.mec.experiment</groupId>
        <artifactId>publisher</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

最佳答案

answer from the possible duplicate我在评论中链接到一个死示例页面的链接。这是 supplement为你。插件配置将属于消费者 pom 内部。

exec:java

Full name:

org.codehaus.mojo:exec-maven-plugin:1.5.0:java

Description: Executes the supplied java class in the current VM with the enclosing project's dependencies as classpath.

Attributes:

Requires a Maven project to be executed. Requires dependency resolution of artifacts in scope: test. The goal is thread-safe and supports parallel builds. Since version: 1.0.

特别请参阅executableDependency以了解您的用例。看起来它将允许您根据其组 ID 和 Artifact 来引用生产者,而不是硬编码路径。

关于java - mvn process-resources 不会拉下使用阴影插件创建的 uber jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41986434/

相关文章:

java - 使用 Java 的 Stack GUI

java - 获取客户端静态IP地址

java - 保留对传递给 super 构造函数的新对象的引用

maven - 在本地存储库中发布自定义库jar文件

java - 尝试设置 Maven Nexus 服务器但收到 "Could not resolve dependencies"

java - Maven 将包含 html 文件的目录打包到 jar 中

java - 在 Maven 中获取版本(次要和主要)

maven - 如何将 tycho p2 存储库构建的结果部署到本地文件系统或本地维护的 p2 存储库上的某个位置

maven - mvn 和 mvn3 命令之间的区别

java - Tomcat 不显示带有集群和 apache 的页面