mvn process-resources 不会拉下使用 shade 插件创建的 uber jar
mvn process-resources doesn't pull down uber jar created with shade plugin
目标:使用 maven shade 插件创建一个可执行的 uber jar,可以在另一个 pom 的 mvn 编译期间执行。
重现步骤:
- 使用下面的 pom 为 "publisher" 组件创建一个 pom.xml。
- 使用 Jenkins 构建来 mvn 部署它(mvn install 也可以)
- 为 "consumer" 添加对 pom.xml 的依赖(下面的 pom)
- mvn 编译消费者
预期行为:
发布者的 Uber jar 已下载到 consumer/target 目录
中的某处
实际:
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 I linked to in the comments has a link to a dead example page. Here's a 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 和工件而不是 hard-coding 路径来引用 producer
。
目标:使用 maven shade 插件创建一个可执行的 uber jar,可以在另一个 pom 的 mvn 编译期间执行。
重现步骤:
- 使用下面的 pom 为 "publisher" 组件创建一个 pom.xml。
- 使用 Jenkins 构建来 mvn 部署它(mvn install 也可以)
- 为 "consumer" 添加对 pom.xml 的依赖(下面的 pom)
- mvn 编译消费者
预期行为: 发布者的 Uber jar 已下载到 consumer/target 目录
中的某处实际: 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 I linked to in the comments has a link to a dead example page. Here's a 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 和工件而不是 hard-coding 路径来引用 producer
。