Maven plugin goals

I am developing a Maven plugin that will provide 5 goals. You can either complete goals 1-4 individually or complete goal5, which will consistently fulfill goals 1-4. I was looking for a way to reuse (i.e., call) one Maven target from inside another, but have not yet found it.

Of course, I could just delegate the goal delegate to ClassX for most of its functionality, and then when goal5 is called, it delegates Class1 ... Class4, but this still involves a certain amount of code duplication in terms of specifying, reading and checking each target configuration.

Is there a way to reuse one target in another?

Thanks Don

+4
source share
3 answers

Is there a way to reuse one target in another?

AFAIK, the Maven API does not offer any opportunities for this, because Maven people do not want to promote a practice leading to a strong connection between plugins, which is considered bad. You will find the background in Re: calling the plugin in another plugin? .

This blog post shows how you can create an instance of Mojo and use reflection to set its field before calling execute.

You can also check out the mojo-executor library.

But be sure to read this topic, I think it is important.

+1
source

Of course, I could just delegate the goal delegate to ClassX for most of its functionality, and then when goal5 is called, it delegates Class1 ... Class4, but this still involves a certain amount of code duplication in terms of specifying, reading and checking each target configuration.

So, why not provide a common class for your other classes in order to verify the purpose? I think the easiest way to do this is to have one target invoke another in your code.

0
source

The "Maven mindset" seems to be the responsibility of the configuration by pom.xml, not the Mojo developer. If you move all of your configuration and such into a common base class, you will end up bypassing this mechanism.

This is similar to what you want - these are subprojects: each of your goals 1-4 lives in its own project, or you can run goal 5, which runs them all. Maybe this can help ?: http://i-proving.com/space/Technologies/Maven/Maven+Recipes/Split+Your+Project+Into+Sub-Projects

If your source trees do not diverge well along the lines of the project, you can do something using profiles (although I have not tried this). Check out the accepted answer here: How to link a plugin’s goal with another plugin .

0
source

Source: https://habr.com/ru/post/1311852/


All Articles