目标:使用 Maven Shade 插件创建一个可执行的 uber jar,可以在另一个 pom 的 mvn 编译期间执行。
重现步骤:
- 使用下面的 pom 为“publisher”组件创建 pom.xml。
- 使用 Jenkins 构建来 mvn 部署它(mvn install 也可以工作)
- 向 pom.xml 添加“consumer”的依赖项(下面的 pom)
- 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/