gpt4 book ai didi

java - 如何将 Maven 模块作为 .class 依赖项而不是 jar 嵌入?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:07:51 25 4
gpt4 key购买 nike

我有一个多模块 maven 项目,用于生成单个 spring boot fat jar。我的项目看起来像这样。

 - Parent Module Aggergator 
- A
- B
- C
- app <-- app.jar is the only thing I want to publish

在我的案例中,模块 A、B、C 仅由应用程序使用,不应发布到 Maven 存储库中。我已将应用程序拆分为多模块项目,因为应用程序中有很多代码,并且需要以这种方式工作。

目前 app.jar 将包含 a.jar, b.jar c.jar

有没有办法告诉 maven 从模块 A、B、C 编译的类应该只插入到 app.jar 类文件夹中,而无需生成 A.JAR、B.JAR、C.JAR?

最佳答案

我将 Maven Shade 插件用于我的多模块项目;它创建一个 JAR 并将每个模块提取到其中,而不是创建多个 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>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<groupId>...</groupId>
<artifactId>pipeline</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<modules>
<module>firehose</module>
<module>gson</module>
<module>lambda</module>
<module>mapper</module>
<module>model</module>
<module>receiver</module>
<module>redshift</module>
<module>reloader</module>
<module>s3</module>
<module>sns</module>
<module>sqs</module>
<module>systemstests</module>
<module>transaction</module>
<module>utility</module>
</modules>

<dependencies>
...
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

pom.xml(JAR):

<?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>

<parent>
<groupId>...</groupId>
<artifactId>pipeline</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>lambda</artifactId>

<dependencies>
...
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<finalName>MyJar</finalName>
</configuration>
</plugin>
</plugins>
</build>
</project>

关于java - 如何将 Maven 模块作为 .class 依赖项而不是 jar 嵌入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51829293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com