【问题标题】:Create test directory only with test libraries仅使用测试库创建测试目录
【发布时间】:2013-11-18 12:58:03
【问题描述】:

我正面临这个问题:

我正在为我们的客户创建装配体。在这个程序集中,我基本上想要 2 个重要的目录:

  • lib/ 包含所有运行时范围的项目依赖项(包括传递性)
  • test/ 具有所有测试范围依赖项(包括传递性),但没有那些已经存在于 lib 文件夹中的依赖项

到目前为止,我最终得到了这个程序集文件(我只包括了重要的部分):

<assembly>
  <id>zip-with-lib-and-test</id>
  <includeBaseDirectory>false</includeBaseDirectory>
  <formats>
    <format>zip</format>
  </formats>
  <dependencySets>
    <dependencySet>
        <outputDirectory>lib</outputDirectory>
        <unpack>false</unpack>
        <useTransitiveDependencies>true</useTransitiveDependencies>
        <useTransitiveFiltering>true</useTransitiveFiltering>
        <useProjectArtifact>true</useProjectArtifact>
    </dependencySet>

    <dependencySet>
        <outputDirectory>test</outputDirectory>
        <unpack>false</unpack>
        <includes>
           <include>group:test-artifact1</include>
           <include>group:test-artifact1</include>
        </includes>
        <useTransitiveDependencies>true</useTransitiveDependencies>
        <scope>test</scope>
    </dependencySet>
  </dependencySets>
</assembly>

有了这个,我有了带有命名工件的测试目录,但是这些测试工件没有传递依赖关系。

我需要像这样进行排除:如果您存在于 lib 工件中,您将不会在测试中。 我试图用 maven-dependency-plugin 做到这一点,但没有运气。

此处不能选择确切的依赖项列表,因为此程序集将位于多个工件上。

【问题讨论】:

  • 我认为仅仅通过汇编插件是不可能完成这个任务的。我会保留您现在拥有的内容并添加另一个步骤,该步骤将根据您的要求对组装结果进行后处理。
  • @AndrewLogvinov 感谢您的评论,请您提供更多细节,您如何看待“另一个会对结果进行后处理的 sptep”?

标签: java maven maven-3 maven-assembly-plugin


【解决方案1】:

Assembly 插件创建一个 zip 存档(它也可以创建一个目录作为输出,但它很麻烦),所以我将它留到最后一步。

  1. 为项目的运行时和测试依赖项的位置声明两个属性(例如,runtime.dirtest.dir)。
  2. 添加两个执行阶段为prepare-package的maven依赖插件:一个用于运行时依赖(应使用includeScope选项),runtime.dir作为输出目录,另一个用于测试依赖,test.dir作为输出目录。因此,runtime.dir 中应该有运行时 + 编译依赖关系,test.dir 中应该有运行时 + 编译 + 提供 + 测试(和系统,如果你有的话)。
  3. 现在是时候添加一些 groovy 脚本了 :) 您的脚本应该列出 test.dir 中的所有文件,并检查每个文件是否存在于 runtime.dir 中;如果是,请从test.dir 中删除此文件。作为在 maven 中使用 groovy 脚本的示例,请参阅 my answer here
  4. 使用程序集插件将所有内容打包到 zip 存档中。

【讨论】:

    猜你喜欢
    • 2019-10-18
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-25
    相关资源
    最近更新 更多