Question

I am new to Maven, we are converting ant based project into Maven project. Every thing is working fine. Additionally we need to compile source code package wise.

To be more clear, we have three packages in src/main/java folder, namely dao, svc and controller. I want to compile dao first and then compile svc by giving dao reference to it, similarly compile controller by giving reference of svc only but not dao.

Finally the goal is to make sure that the controllers are not using any of the dao classes, they can use svc classes only. If this condition fails, Maven build has to be failed.

Please suggest.

Was it helpful?

Solution

It sounds like you need a multi-module maven project. Create a parent project, whose task is simply to aggregate your three modules and to provide one thing to build. Create one module for each of your packages, then define dependencies between those modules in the individual POM files.

The Maven build system is clever enough to know in which order to build the modules, based on the dependencies you declare between them. In cases where you don't define a dependency (e.g. between controller and dao), the controller module cannot access classes in the dao module.

The final source layout will be something like:

your-project
your-project/pom.xml   <--- parent POM

your-project/dao
your-project/dao/pom.xml
your-project/dao/src/main/...

your-project/svc
your-project/svc/pom.xml
your-project/svc/src/main/...

your-project/controller
your-project/controller/pom.xml
your-project/controller/src/main/...

OTHER TIPS

To be more clear, we have three packages in src/main/java folder, namely dao, svc and controller. I want to compile dao first and then compile svc by giving dao reference to it, similarly compile controller by giving reference of svc only but not dao.

Judging by your requirements, I think more or less you need to setup a maven based Multi Module project. Take a look at these links

  1. Link 1
  2. Link 2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top