I am using the maven-invoker-plugin to run integration tests against a Maven plugin. I am able to use a verify.groovy
script to assert statements about the artifacts generated by my test projects; this is all working fine.
Now I want to test that, under certain conditions, my plugin causes a build failure. To test this I want to create a module under the integration-test
directory that is deliberately broken. Then I would like to assert that (a) the build of that module fails, and (b) the error message is what I expect it to be.
I have found that the failure of the failure of this test project always causes the main Maven build to fail, and my post-build verify script is not executed. Is there a way for me to achieve what I want?
The straightforward approach, as mentioned @khmarbaise, is to create an invoker.properties
file in the test directory and include the following line in it:
invoker.buildResult = failure
This configuration allows you to customize the behavior of the Maven Invoker Plugin by specifying that the build result should be considered as a failure. The invoker.properties
file is a handy way to configure various settings for the plugin and tailor its behaviour according to your requirements. You can read more about the file right here.
Another approach you can take is to implement a property in your plugin that prevents exceptions from being thrown during plugin execution. This can be achieved by adding the following configuration to your plugin's POM file:
<configuration>
<failOnError>false</failOnError>
</configuration>
By setting failOnError
to false
, you can handle exceptions gracefully and improve the user experience. This approach not only helps in checking integration tests but also allows users to choose whether to ignore exceptions in your plugin.
Implementing this property can be beneficial in scenarios where it's necessary to proceed with the execution even if an error occurs. It provides more flexibility and control over how exceptions are handled within your plugin.
To validate the text generated by your plugin, you can utilize a post-build script, such as a verify.groovy
file located in the integration test directory. This script can be used to verify the contents of the output log:
String log = new File(basedir, 'build.log').text;
log.contains("BUILD SUCCESS")
You can read more about post-build scripts more right here.