代码之家  ›  专栏  ›  技术社区  ›  Chris Williams

maven jar插件包含vs排除

  •  8
  • Chris Williams  · 技术社区  · 16 年前

    我有一个包含maven jar插件部分的pom文件。它为testjar目标运行,目前排除了几个目录:

    <excludes>
         <exclude>...</exclude>
         <exclude>...</exclude>
         <exclude>somedir/**</exclude>
     </excludes>
    

    我需要在somedir目录中包含一个文件,但不包含somedir目录中的其余文件。我读到include优先于excludes,所以我添加了如下内容(以前没有include部分):

    <includes>
        <include>somedir/somefile.xml</include>
    </includes>
    

    最后创建一个jar文件进行测试,其中只有几个文件(只是META-INF中的内容)。我包含的文件也不在jar中。我所期望的是一个jar,它与我的includeschange之前创建的jar完全相同,只有一个附加文件。

    1 回复  |  直到 16 年前
        1
  •  11
  •   Pascal Thivent    16 年前

    首先,如果你没有具体说明 includes **/** 作为默认模式(请参见 o.a.m.p.j.AbstractJarMojo )也就是说,它将包括一切。如果你覆盖这个默认模式,插件显然只包含你告诉他要包含的内容。

    第二,目录扫描在最后由 o.c.p.u.DirectoryScanner 这个类的javadoc是这么说的:

     * The idea is simple. A given directory is recursively scanned for all files
     * and directories. Each file/directory is matched against a set of selectors,
     * including special support for matching against filenames with include and
     * and exclude patterns. Only files/directories which match at least one
     * pattern of the include pattern list or other file selector, and don't match
     * any pattern of the exclude pattern list or fail to match against a required
     * selector will be placed in the list of files/directories found.
    

    excludes 只有图案 一个 文件将与包含模式匹配,但也与排除模式匹配,因此不会被选中,您将得到一个几乎为空的存档(只有默认清单,请参阅 o.a.m.p.j.AbstractJarMojo#createArchive()

    包括 <exclude>somedir/**</exclude> ,或使用 包括 仅限,或使用 排除 仅限)。

    推荐文章