为maven目录结构生成的源文件的位置 [英] Location of generated source files for maven directory structure

查看:276
本文介绍了为maven目录结构生成的源文件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了 src / main / java 文件夹外,我们有一个文件夹包含一些生成的主要来源所需的java源文件。在需要时,手动调用代码生成。生成的来源是检查到源回购。所有内容都将被构建和打包在一起。



生成的Java 的最佳位置是与主要来源一起编译?它应该是:


  • / src / generated / java (遵循相同的命名用于集成测试的 src / testInt / java

  • / generated-src / main / java (与相冲突)src目录包含用于构建项目的所有源材料
  • / src / main / generated-java (well ... generated-java 不是类型)

  • ...?



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

谢谢。

回答



正如@ Absurd-Mind所建议的那样,我们正在考虑的方向是将源代码拆分成子模块(它在gradle中很好用)。所以,生成的源代码和其他相关的源代码将进入它自己的子模块(它们将生成单独的工件),其余的将会在其他子模块中使用,这个子模块使用这个模块。谢谢。

解决方案

我认为位置取决于源代码的生成和处理方式。


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

  2. 源代码由外部工具或类似工具手动生成:我将使用 generated / src / main / java / generated / src / test / java / generated / src / main / resources / 等等。应该检入此代码。一个好处是,只要您看到顶级目录名称是 generated ,就知道下面的所有文件/目录也会生成。你还有顶层目录下的标准maven目录结构。另一点是清理很简单,只需删除 generated 并重新创建它,而不需要查看许多其他目录(例如: src / main / generated-java 和src / test / generated-java)。 strong> EDIT :另一个不错的解决方案是创建一个只包含生成的源文件的项目,比如 myproject-generated-1.0.3.jar 。该项目将成为您实际应用程序的依赖项。然后,您只需将您生成的源代码int src / main / java


    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.

    解决方案

    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.

    这篇关于为maven目录结构生成的源文件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆