gpt4 book ai didi

java - maven未将依赖项打包到jar中

转载 作者:行者123 更新时间:2023-11-30 04:22:29 25 4
gpt4 key购买 nike

问题

我有一个嵌套的多个模块(正确的术语?)Maven 项目,并且当我 mvn clean package 时,其中一个模块的依赖项没有与 jar 一起打包。

该项目实际上是我没有编写的其他内容的分支,并且在该过程中的某个地方我破坏了构建过程,但我似乎无法找出我做了什么。

项目结构如下:

    • 分布(父=根)
    • child1(父级 = root)<-- 未打包此依赖项
    • child2(父=根)

pom 如下(很抱歉将它们全部发布到这里,但我真的不知道在哪里看):

<groupId>com.something</groupId>
<artifactId>root</artifactId>
<packaging>pom</packaging>

<modules>
<module>child1</module>
<module>child2</module>
<module>distribution</module>
</modules>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
</plugins>
</build>

分布

<parent>
<groupId>com.something</groupId>
<artifactId>root</artifactId>
</parent>

<artifactId>distribution</artifactId>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors
<descriptor>src/main/assembly/distribution.xml</descriptor>
</descriptors>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

child 1

<parent>
<groupId>com.something</groupId>
<artifactId>root</artifactId>
</parent>

<artifactId>child1</artifactId>
<packaging>jar</packaging>

<dependencies>
many dependencies here...
</dependencies>

child 2

<parent>
<groupId>com.something</groupId>
<artifactId>root</artifactId>
</parent>

<artifactId>child2</artifactId>
<packaging>jar</packaging>

<dependencies>
many dependencies here...
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

distribution.xml

<id>package</id>
<formats>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>..</directory>
<outputDirectory>.</outputDirectory>
<fileMode>0644</fileMode>
<includes>
<include>README</include>
<include>CHANGELOG</include>
<include>LICENSE.txt</include>
<include>NOTICE.txt</include>
</includes>
</fileSet>
<fileSet>
<directory>../bin</directory>
<outputDirectory>bin</outputDirectory>
<fileMode>0755</fileMode>
</fileSet>
<fileSet>
<directory>../workloads</directory>
<outputDirectory>workloads</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includeSubModules>true</includeSubModules>
<sources>
<includeModuleDirectory>true</includeModuleDirectory>

<fileSets>
<fileSet>
<directory>.</directory>
<fileMode>0644</fileMode>
<includes>
<include>README</include>
</includes>
</fileSet>
<fileSet>
<directory>src/main/conf</directory>
<outputDirectory>conf</outputDirectory>
<fileMode>0644</fileMode>
</fileSet>
<fileSet>
<outputDirectory>lib</outputDirectory>
<directory>target</directory>
<includes>
<include>*.jar</include>
</includes>
<fileMode>0644</fileMode>
</fileSet>
</fileSets>
</sources>
</moduleSet>
</moduleSets>

注意:代码位于 github 上,如果有人有时间并希望查看真实的项目,我很乐意提供存储库的链接!

最佳答案

我相信这是设计使然。这就是 jar 的工作方式。如果您要将依赖项打包到 jar 中,它们无论如何都不会工作。解决办法是使用shade插件制作一个uberjar。 Here's a tutorial on how.

那个maven-assembly-plugin插件也可以做到这一点,但它没有那么多功能。无论哪种方式,如果您将其添加到 child1 pom 中,它也会打包依赖项。

关于java - maven未将依赖项打包到jar中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16703110/

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