【问题标题】:How to add artifacts from a submodule build directory?如何从子模块构建目录添加工件?
【发布时间】:2018-12-18 12:24:04
【问题描述】:

我的项目结构如下:

project-root
    |
    |__lib
    |   |
    |   |__target
    |   |    |____lib.jar
    |   |    |____lib.so
    |   |___src
    |   |    |____ ...
    |   |
    |   |_pom.xml
    |
    |___model
    |     |
    |     |_pom.xml
    |     |
    |    ...
    |
    |__pom.xml

所以我有 2 个模块项目:lib 和 model,其中模型使用 maven-assembly-plugin 生成 tar.gz 分布。问题是 lib 的构建导致生成本机库lib.so,需要将其复制到tar.gz 中才能使用。

如何使maven-assembly-plugin 将一个子模块的构建目录中的工件包含到目录中(例如,在我的情况下为tar.gz)

【问题讨论】:

    标签: java maven jar


    【解决方案1】:

    在您的程序集descriptor 文件中,您可以将 lib.so 文件添加到您的 tar 包中。 (我假设你已经有一个 maven 程序集的描述符来创建 tar.gz 包)

    我在这里修改默认的jar-with-dependencies 描述符作为示例。

    <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
      <id>custom-descriptor</id>
      <formats>
        <format>jar</format>
      </formats>
      <includeBaseDirectory>false</includeBaseDirectory>
      <dependencySets>
        <dependencySet>
          <outputDirectory>/</outputDirectory>
          <useProjectArtifact>true</useProjectArtifact>
          <unpack>true</unpack>
          <scope>runtime</scope>
        </dependencySet>
      </dependencySets>
    
      <!-- You need to add following to your current descriptor -->
      <fileSets>
        <fileSet>
          <directory>${project.build.directory}/../../lib/target</directory>
          <outputDirectory>lib</outputDirectory>
          <includes>
            <include>*.so</include>
          </includes>
        </fileSet> 
      </fileSets>
    
    </assembly>
    

    我们需要给出目录部分的相对路径。 (我不知道未发布文件的任何其他方式) OutputDirectory 确定文件将在创建的存档中复制到哪个文件夹中。 (如果你想把它放在存档的根目录中,你可以把它保留为“/”。

    使用汇编插件时(你可能有这样的)

    <build>
        <plugins>
          <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
              <descriptors>
                   <!-- descriptor file previously created. -->
                   <descriptor>custom-descriptor.xml</descriptor>
              </descriptors>
            </configuration>
            <executions>
              <execution>
                <id>make-assembly</id>
                <phase>package</phase> 
                <goals>
                  <goal>single</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
        .....
      </build>
    

    在这种情况下,custom-descriptor.xml 文件位于 pom.xml 文件旁边。如果它放在其他地方,则应在描述符标签中给出相对路径。

    Ps:如果 lib 是在模型之前构建的,这将起作用。

    【讨论】:

      猜你喜欢
      • 2012-02-20
      • 1970-01-01
      • 2021-05-02
      • 1970-01-01
      • 2019-09-17
      • 1970-01-01
      • 2018-11-29
      • 2019-11-10
      • 2019-10-26
      相关资源
      最近更新 更多