Maven Project Design Guidelines

There are some items to keep in mind when creating a maven build script for your application:

  • A maven script should not change source code at build time. If you are using maven filters, then this is probably the case!
  • Once checked out, a maven application should build without errors, first try. It should not require specific set ups.
  • A maven project should not contain generated code. Code must be generated in a separate maven project, published to Nexus (artifact store) and then imported into your project as a dependency. For example, say you have a module that generates a service contract from a wsdl file. This generated code is not checked into version control (should not!). On a different machine, the maven build will fail initially due to compile errors. One would have to run the code generator, and then run the maven build for the build to pass. This violates point number 2.
  • Never mix business logic and configuration in the same artifact. Environment specific configuration should go into a config module.
  • EJB libraries must not be bundled into the applications whose services they expose. This is due to versioning. A change in the application that does not affect the API’s external interface, should not result in a version bump of the EJB library. In other words, the library version should only change when the API changes. Clients using the EJB library do not care about application-internal changes, which is why it is such bad practise to bundle the library with the application. (Though it does make sense on first thought).

Thanks to Tor for sharing his knowledge and giving me these pointers! Will come in handy.