fakefla
fakefla

Reputation: 186

Maven Generated Sources inside Different Project

I have a Java web project that is built using Maven. The project has some annotated classes to generate some sources at build time using a template (velocity). Everything works well so far, I'm using the generated sources flawless.

Right now I need to use those generated classes in a different project. I'm wondering how can I tell maven to package those sources in an additional jar. I would like to use that generated jar in both my main project and the new one as a new dependency.

Any Ideas?

Thanks!

Upvotes: 1

Views: 640

Answers (1)

khmarbaise
khmarbaise

Reputation: 97349

Simplest solution is to create a separate project which contains only the generated parts which will by default create a jar file as usual which gives you simple the possibility to reuse that in different other projects. With the following structure this is simple to solve.

  +-- root (pom.xml)
        +--- generated (pom.xml)
        +--- main (pom.xml)
        +--- other (pom.xml)

In you main project just simply define a dependency to your generated project like

<dependency>
  <groupId>what.ever.group</groupId>
  <artifactId>generated</artifactId>
  <version>${project.verison}</version>
</dependency>

and the same in your other module.

Upvotes: 1

Related Questions