exec-maven-plugin icon indicating copy to clipboard operation
exec-maven-plugin copied to clipboard

Build failure when used in "clean" scope in fresh build

Open raphw opened this issue 5 years ago • 3 comments

In a multi-module build, due to the use of requiresDependencyResolution = ResolutionScope.TEST, it is impossible to reliably use the plugin before the install phase of dependant modules in the same project. This can be a problem when using the plugin in the clean phase where it can be useful to clean up external resources that are created by the plugin in other phases.

The error happens when building a snapshot version for the first time where intra-project dependencies might not yet exist. When triggering the maven-exec-plugin, Maven will attempt to resolve the dependencies for the module where no dependent package was yet created before the package phase. Therefore, dependency resolution will fail. This is independant of the dependencies being required by the plugin.

As a possible work around, one could create a subclass without any code of its own such as:

@Mojo( name = "raw-exec", 
  threadSafe = true, 
  requiresDependencyResolution = ResolutionScope.NONE )
public class RawExecMojo extends ExecMojo { }

This way, one could use the plugin in the clean phase.

Such a solution would remedy the issue of people often using mvn clean package even on a fresh project where any clone with subsequent build results in an error.

raphw avatar Nov 28 '19 20:11 raphw

Hi @raphw! I'm hitting the same problem.

As a possible work around, one could create a subclass

Could you expand a bit on this? Are you saying this should be done at exec-maven-plugin level, or in our multi-module project?

There might also be requiresDependencyCollection to consider.

lppedd avatar Sep 22 '22 16:09 lppedd

I argue this needs fixing in Maven, yes.

raphw avatar Sep 22 '22 17:09 raphw

@raphw thanks. This kind of multi-module issue is making me go crazy. It's much more noticeable when you run a CI pipeline.

If you start with projects a and b, and then you deliver c, making b dependent on it, you'll have to run mvn install again. At this point you'll end up with a pipeline which always uses install, wasting time for nothing.

lppedd avatar Sep 22 '22 17:09 lppedd