Enterprise grade Java.
You'll read about Conferences, Java User Groups, Java, Integration, Reactive, Microservices and other technologies.

Wednesday, July 22, 2009

Adding additional Source Folders to Maven Project

06:13 Wednesday, July 22, 2009 Posted by Markus Eisele
, , , ,
Most projects today have at least one part, that is generated in anyway. This is not too easy to integrate with maven. Mostly the generator's build relys on ant. Therefore it's always a discussion, where to place the build and how to trigger it. The most easiest way is to have a separate java eclipse project that builds with ant and copying the generated ressources to a /gen/ folder within your maven project. Beside the disadvantage, that you have a possible stale version of the generated sources checked in with your repository there are also some advantages, too.
Even if the majority of your team memvers do not have the generator project setup, they can still develop. Beside this, you skip the mostly tricky part of shipping a bunch of additional eclipse plugins to the rest of the team and you can keep the model itself under control of a selected group of persons. Anyway, if you have such a setup, it is no good idea to copy the generated sources to your /main/java folder. It should be obvious to the developers, that there are generated sources in the project. A practical workaround for this is to have different java src folders in your projects. This could be a /main/gen folder for example. In order to tell maven about it, you need to add additional resources to your projects pom-file.
Resource folder are ment for resources and not for java files. Therefore this is quite a bit like a workaround. But it works :)
The following snippet assumes three src folders in your project.

<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include> **/*.java </include>
<include> **/*.properties </include>
<include> **/*.xml </include>
</includes>
</resource>
<resource>
<directory>src/main/gen</directory>
<includes>
<include> **/*.java </include>
<include> **/*.properties </include>
<include> **/*.xml </include>
</includes>
</resource>
<resource>
<directory>src/main/test</directory>
<includes>
<include> **/*.java </include>
<include> **/*.properties </include>
<include> **/*.xml </include>
</includes>
</resource>
</resources>