简体   繁体   中英

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM