加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – maven-jar-plugin包含vs排除

发布时间:2020-12-16 07:50:21 所属栏目:百科 来源:网络整理
导读:我有一个现有的pom文件,其中包含一个maven-jar-plugin部分.它运行测试jar目标,目前不包括几个目录: excludes exclude.../exclude exclude.../exclude excludesomedir/**/exclude /excludes 我需要在somedir目录中包含一个文件,但遗漏somedir目录中的其余文
我有一个现有的pom文件,其中包含一个maven-jar-plugin部分.它运行测试jar目标,目前不包括几个目录:
<excludes>
     <exclude>...</exclude>
     <exclude>...</exclude>
     <exclude>somedir/**</exclude>
 </excludes>

我需要在somedir目录中包含一个文件,但遗漏somedir目录中的其余文件.我已经读过,包括优先于排除,所以我添加了类似下面的内容(之前没有包含部分):

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

这最终会创建一个jar文件进行测试,其中只有几个文件(只是META-INF中的东西).我包含的文件也不在jar中.我期望的是一个jar,它与我在包含一个额外文件的更改之前创建的jar相同.

我在这里想念的是什么?

首先,如果你没有指定任何包含,那么maven jar插件将使用** / **作为默认模式(参见 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.

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

我不能在这里给你确切的解决方案,但你显然需要重新考虑包含/排除文件的方式(例如添加更多包含模式,删除< exclude> somedir / **< / exclude>或仅使用包含,或仅使用排除).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读