Java Maven 目录结构的生成源文件的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22912900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 18:55:17  来源:igfitidea点击:

Location of generated source files for maven directory structure

javamavengradledirectory-structure

提问by igr

Besides src/main/javafolder, 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 checkedinto the source repo. Everything will be built and packed together.

除了src/main/java文件夹之外,我们还有一个文件夹,其中包含一些主要源代码所需的生成的 Java 源代码。需要时手动调用代码生成。生成的源被入源存储库。一切都将被构建和打包在一起

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

将与主要源代码一起编译的生成的 Java源代码的最佳位置是什么?应该是:

  • /src/generated/java(following the same naming logic for src/testInt/javafor 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-javais not a type)
  • ...?
  • /src/generated/java(遵循相同src/testInt/java的集成测试命名逻辑)
  • /generated-src/main/java(与“src 目录包含用于构建项目的所有源材料”相冲突)
  • /src/main/generated-java(嗯......generated-java不是一种类型)
  • ……?

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?

第一个选项似乎最适合这种情况。你怎么认为?Maven 文档中是否有任何描述这种情况的内容(我忽略了)?你知道任何具有类似结构的回购吗?

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.

正如@Absurd-Mind 所建议的,我们正在考虑的方向是将源拆分为子模块(这在 gradle 中效果很好)。因此,生成的源和其他一些相关的源将进入其自己的子模块(它们将产生单独的工件),其余的将进入使用此模块的其他子模块。谢谢你。

采纳答案by Absurd-Mind

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 targetdirectory 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 generatedyou 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 generatedand recreate it, without looking through many other directories (like in your example: src/main/generated-javaand src/test/generated-java).

  1. 源代码是在构建过程中自动生成的:然后我会使用target/main/java/target/test/java/等等。这段代码不会被签入到 CVS 中,因为你可以很容易地重建它。如果你清理你的项目,target目录将被删除,源代码将被重建。

  2. 源代码是由一个外部工具或类似手动生成:我会使用generated/src/main/java/generated/src/test/java/generated/src/main/resources/等。应该签入此代码。好处是,一旦您看到顶级目录名称,generated您就会知道下面的所有文件/目录也已生成。此外,您在顶级目录下拥有标准的 maven 目录结构。另一点是清理很容易,只需删除generated并重新创建它,而无需查看许多其他目录(如您的示例:src/main/generated-java和 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.

编辑:另一个不错的解决方案是创建一个 maven 项目,它只包含生成的源,如myproject-generated-1.0.3.jar. 该项目将成为您实际应用程序中的依赖项。然后你就可以把你生成的源 int src/main/java

回答by sus007

In Maven project source file store inside src/main/java, src/main/resourcesand test class store inside src/test/java.
In Maven generated code (Compile code) stored into target/folder.
When you build your Maven project, all generated code to be updated in target folder.

在Maven项目的源文件存放在里面src/main/javasrc/main/resources而测试类存放在里面src/test/java
在 Maven 生成的代码(编译代码)中存储到target/文件夹中。
当您构建 Maven 项目时,所有生成的代码都会在目标文件夹中更新。

回答by bhdrkn

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

据我所知,生成的源没有标准的文件夹结构。在我的项目中,我更喜欢src/gen/java某种符号。