简体   繁体   English

使用Maven程序集插件检测缺少的包含文件

[英]Detecting missing included file with Maven assembly plugin

I use Maven assembly plugin to build my project with the following descriptor: 我使用Maven程序集插件通过以下描述符构建我的项目:

    <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>src</id>
  <formats>
    <format>tar.gz</format>
    <format>tar.bz2</format>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.basedir}</directory>
      <includes>
        <include>README*</include>
        <include>LICENSE*</include>
        <include>NOTICE*</include>
        <include>pom.xml</include>
      </includes>
      <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
    <fileSet>
      <directory>${project.basedir}/src</directory>
      <useDefaultExcludes>true</useDefaultExcludes>
    </fileSet>
  </fileSets>
</assembly>

Now, if one include is missing (suppose that I don't have any "README*" or "pom.xml" file in the example), I don't have any error. 现在,如果缺少一个包含(假设示例中我没有任何“ README *”或“ pom.xml”文件),则我没有任何错误。

Is there a way to get an error or a warning during the build if an included file is missing ? 如果缺少所包含的文件,是否有办法在构建过程中得到错误或警告?

For that, you need to have a maven enforcer plugin. 为此,您需要一个Maven强制实施器插件。

This rule checks that the specified list of files exist. 该规则检查指定的文件列表是否存在。

you need to have something like this. 你需要有这样的东西。

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-enforcer-plugin</artifactId>
  <version>3.0.0-M2</version>
  <executions>
    <execution>
      <id>enforce-license</id>
      <goals>
        <goal>enforce</goal>
      </goals>
      <configuration>
        <rules>
          <requireFilesExist>
            <files>
              <file>${project.basedir}/README*</file>
              <file>${project.basedir}${project.basedir}/LICENSE*</file>
              <file>${project.basedir}${project.basedir}/NOTICE*</file>
             <file>${project.basedir}${project.basedir}/pom.xml</file>
            </files>
          </requireFilesExist>
        </rules>
       <fail>true</fail>
      </configuration>
    </execution>
  </executions>
</plugin>

Also see: maven enforcer and requireFilesExist 另请参见: maven 强制程序requireFilesExist

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM