Maven-通过Maven程序集插件将依赖关系转化为其他依赖关系

时间:2019-11-03 15:26:31

标签: java maven dependencies

我有一个带有两个依赖项的Maven POM项目test-module3:依赖项测试模块1和依赖项测试模块2。

依赖项test-module2也具有test-module1作为依赖项,其作用域设置为可编译,但是它没有配置Maven Shade插件或Maven组件插件。

现在,我想使用test-module3构建依赖关系test-module2。因此,我配置了Maven Assemby插件。效果很好。但是,依赖性测试模块2中缺少依赖性测试模块1。

我如何配置Maven Assemby插件或test-module3的任何其他插件,以便将test-module1遮盖到test-module2中?

这是我的POM:

<?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>test</groupId>
        <artifactId>test-project</artifactId>
        <version>1.0.0</version>
    </parent>
    <artifactId>test-distribution</artifactId>
    <packaging>pom</packaging>
    <dependencies>
        <dependency>
            <groupId>test</groupId>
            <version>${project.version}</version>
            <artifactId>test-module1</artifactId>
        </dependency>
        <dependency>
            <groupId>test</groupId>
            <version>${project.version}</version>
            <artifactId>test-module2</artifactId>
        </dependency>
    </dependencies>
    <build>  
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>src/assembly/distribution.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>  
</project>

distribution.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
  <id>distribution</id>
  <formats>
      <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
      <dependencySet>
      </dependencySet>    
  </dependencySets>
</assembly>

test-module1的POM:

<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>test</groupId>
        <artifactId>test-project</artifactId>
        <version>1.0.0</version>
    </parent>
    <artifactId>test-module1</artifactId>
    <packaging>jar</packaging>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
</project>

test-module2的POM:

<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>test</groupId>
        <artifactId>test-project</artifactId>
        <version>1.0.0</version>
    </parent>
    <artifactId>test-module2</artifactId>
    <packaging>jar</packaging>
    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>test</groupId>
            <artifactId>test-module1</artifactId>
            <version>${project.version}</version>
        </dependency>
    </dependencies>
</project>

我的目标是将test-module1放在ZIP文件夹中,将test-module2放在ZIP文件夹中,但是test-module2还应该包含test-module1。

0 个答案:

没有答案