I wrote this up for the NetRexx mailing list, but it’s a good basics article for anyone wanting to get a quick glance at Maven‘s operations.Â I’m not trying to come up with a better Maven, I’m just giving a quick description.
Maven 102: Advanced Basics
Alternate title:Â What you need to do to be a good Maven citizen
Java module layout
Here is the default layout for a java/jar maven module.Â You can reconfigure source and output directories, but you may not want to, as I’ll discuss in a second.
src/main/java src/main/resources src/test/java src/test/resources
target target/classes target/test-classes
A general flow for Maven in such a project would be to:
- compile src/main/java to target/classes
- copy src/main/resources to target/classes
- compile src/test/java to target/test-classes
- copy src/test/resources to target/test-classes
- run unit tests, output to target/surefire-reports
- build jar, source jar, and test jars, place in target
Again, you can change much of this, but with Maven, the more you fight with it, the more you will have to fight with it.Â It kind of snowballs and will cause annoyances down the line, during releases and documentation and site generation and such.
It is not terrible to set up a repository, but the holy grail (for the users, anyway) is to get your libraries uploaded to Maven Central — this will make the process quite seamless for adding a new compiler to a project because access to Maven Central is basically required for Maven operation.
Custom Language Compilation
Another important task for easy maven integration is compilation.Â This will generally require a special maven plugin that can essentially executeÂ the custom language compiler and conform to something similar to the input and output directories above.Â This is not too tricky, especially if there is a java entry point to do the work.
Related to this is a topic of modularity:Â how do you break up a project?Â How do you resolve circular references across multiple langugaes? For example, you will generally get yourself into trouble if you have:
src/main/java src/main/netrexx src/main/javafx
all in the same module, and are trying to compile them all at once.Â Unless you have a single compiler that can process all your source at once, this won’t work.Â You will be far happier to make multiple modules, use maven to describe the dependencies, and do one language at a time.