I am developing a Mojo(think it as just a usual class) for my custom Maven Plugin. There is an Abstract Mojo at top. I have some other custom Mojos in example which makes server side includes. I have some static variables and some util methods in example get operating system name, fix file separator in order to used operating system etc. I have created an abstract Base Mojo that extends Abstract Mojo and put every common things inside it. When I create a Mojo (i.e. server side includer) I extend it from my Base Mojo. However should I think that I should separate variables and util methods or not and what kind of pattern I should follow.

To make it clear there is:

  • AbstractMojo at top by default (I can not change it)
  • BaseMojo an abstract class that extends AbstractMojo that has util methods and static system variables
  • CustomMojo extends BaseMojo and does its responsibility.

Any ideas how to implement a design for my needs?

  • Cannot help unless you explain what a Mojo is. Apr 1, 2013 at 12:52

2 Answers 2


I'm wondering, why this was migrated. But anyway:

You shouldn't put everything in a base mojo. That practically makes reusing that code impossible. Just think of the mojo growing and you need to split that mojo up into separate classes. You can't do that if that code has a dependency on the base class of the mojo.

You should create services that provide the functionality you currently have in your base mojo. They are reusable and therefore accessible from other places.

As a general rule of thumb:
YAGNI - You aint gonna need a member declaration in a class that is only intendend to be used by deriving classes. How do you know that it is really used?


The pattern depends on what the Mojo classes are doing. The util methods should be moved to a helper or utility class or encapsulated within the class that uses them. Unless BaseMojo is providing common implementations for a behavior which may be over ridden in Custom Mojos, it is not required.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.