如何收集多模块的所有依赖关系

时间:2019-01-23 03:43:52

标签: maven pom.xml maven-plugin maven-assembly-plugin

收集多模块的所有依赖项

我有如下所示的模块:

parent
  |_module1
  |_module2
  |_distribution

父pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project>
    <modules>
        <module>module1</module>
        <module>module2</module>
    </modules>

    <profiles>
        <profile>
            <id>distribution</id>
            <modules>
                <module>distribution</module>
            </modules>
        </profile>
    </profiles>
</project>

分发pom.xml

<project>
    <artifactId>distribution</artifactId>
    <packaging>pom</packaging>
    <build>
        <plugins>
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>3.1.1</version>
                <executions>
                        <execution>
                        <id>copy-dependencies</id>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <inherited>false</inherited>
                        <configuration>
                            <includeScope>compile</includeScope>
                            <outputDirectory>${project.build.directory}/dependencies</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

我想基于配置文件收集所有依赖项。

profile1:所有依赖项都包括module1和module2 jar本身。

profile2:所有依赖项不包括module1和module2 jar本身。 Profile2主要用于开发环境。我们只需要服务器中的依赖项jar,就可以使用Eclipse即时将module1和module2部署到服务器上。

我试图使用maven-assembly来获取包括模块1和模块2在内的所有依赖关系,但是我不知道如何在maven组件中有条件地包含/排除模块jar。

谢谢

0 个答案:

没有答案