Building a maven assembly, I left with something like this:
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>LICENSE.md</include>
...
How can I enforce the existence of
LICENSE.md
?
In the given example, no warning is thrown if this file is not present, ideally, I would like to fail the build.
Whenever you want to fail the build according to different constraints, you should look into the Maven Enforcer Plugin. This plugin allows the configuration of rules that are checked, and if any of them is not passing, it makes the build fail.
There is a built-in rule to check for the existence of a file, called requireFilesExist
:
This rule checks that the specified list of files exist.
As such, in order to fail the build if the file LICENSE.md
is not present, you could have:
<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-license</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireFilesExist>
<files>
<file>${project.basedir}/LICENSE.md</file>
</files>
</requireFilesExist>
</rules>
</configuration>
</execution>
</executions>
</plugin>
This runs by default in the validate
phase, which is the first phase invoked in the build, so that the build will fail fast if the file isn't present.