0

问题

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

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

项目结构如下:

    • 分布(父 = 根)
    • child1 (parent = root) <-- 没有为此打包依赖项
    • child2(父母=根)

这些 poms 如下(很抱歉将它们全部发布在这里,但我真的不确定在哪里看):

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

孩子1

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

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

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

孩子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>

分布.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 上,如果有人有时间和渴望查看真实项目,我很乐意提供存储库的链接!

4

1 回答 1

2

我相信这是设计使然。这只是罐子的工作方式。如果您要将依赖项打包到 jar 中,它们无论如何都不会工作。解决方法是使用shade插件制作一个uberjar。 这是有关如何操作的教程。

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

于 2013-05-22T23:26:12.023 回答