Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of generated source files for maven directory structure

Besides src/main/java folder, we have one folder that contains some generated java sources that are required for the main sources. Code generation is invoked manually, when needed. Generated source is checked into the source repo. Everything will be built and packed together.

What would be the best location for generated java sources that are going to be compiled together with main sources? Should it be:

  • /src/generated/java (following the same naming logic for src/testInt/java for integration tests)
  • /generated-src/main/java (in collision with "The src directory contains all of the source material for building the project")
  • /src/main/generated-java (well... generated-java is not a type)
  • ...?

The first option seems like the most appropriate one for this case. What do you think? Is there anything in Maven docs that describes this situation (that I have overlooked)? Do you know any repo with similar structure?

Thank you.

Answer

As suggested by @Absurd-Mind, direction we are thinking about is to split the source into the submodules (which works nice in gradle). So, the generated source and some other related source will go into its own submodule (they will produce the separate artifact) and the rest will go in other submodule, that uses this one. Thank you.

like image 337
igr Avatar asked Apr 07 '14 12:04

igr


People also ask

What directory structure contains the source code of your artifact in Maven?

maven-project/src/main – contains source code and resources that become part of the artifact.

What is Maven folder structure?

Maven project structure defines a folder in order to store all resources and files needed by a web application.

What is Maven generate sources?

The “maven-source” plugin is used to pack your source code and deploy along with your project. This is extremely useful, for developers who use your deployed project and also want to attach your source code for debugging.

Where are the .class files of a Maven project located?

Take a look at the default folder layout in maven. The Maven Way is to put the source files (*. java) into src/main/java, the resources src/main/resources. The unit test classes src/test/java and src/test/resources after compiling it will be put into target/classes or for the tests target/test-classes.


2 Answers

I think the location depends on how the source is generated and handled.

  1. The source code is generated automatically during the build process: Then i would use target/main/java/, target/test/java/ and so on. This code is not checked in into CVS since you can rebuild it fairly easy. In case you clean your project the target directory will be removed and the source will be rebuild.

  2. The source code is generated manually by an external tool or similar: I would use generated/src/main/java/, generated/src/test/java/, generated/src/main/resources/ and so on. This code should be checked in. A benefit is, as soon you see that the top-level directory name is generated you know that all files/directories below are also generated. Also you have the standard maven directory structure under the top-level directory. Another point is that clean-up is easy, just delete generated and recreate it, without looking through many other directories (like in your example: src/main/generated-java and src/test/generated-java).

EDIT: Another nice solution would be to create a maven project which only contains the generated source like myproject-generated-1.0.3.jar. This project would be a dependency in your real application. Then you would just put your generated source int src/main/java.

like image 179
Absurd-Mind Avatar answered Oct 12 '22 22:10

Absurd-Mind


As much as i know there is no standard folder structure for generated sources. In my projects, i prefer src/gen/java kind of notation.

like image 24
bhdrkn Avatar answered Oct 12 '22 22:10

bhdrkn