问题描述
我使用 Apache Thrift 在target/generated-sources
中生成代码.
I use Apache Thrift to generate code in target/generated-sources
.
Thrift编译器生成一个名为gen-java
的目录,其中包含所有Java代码.当我执行mvn compile
时,代码在target/generated-source/gen-java
中正确生成,但是在编译阶段,它抱怨找不到在gen-java
中定义的类.
The Thrift compiler produces a directory named gen-java
which contains all the Java code. When I execute mvn compile
, the code is generated correctly in target/generated-source/gen-java
, but in compilation phase, it complains can't find the classes which defined in gen-java
.
据我了解,Maven 2自动添加生成的源代码,对吗?
In my understanding, Maven 2 automatically adds generated sources, is that right?
如果我的测试代码也依赖于generated-sources
,我必须手动指定编译器包括什么吗?
And what if my testing code also depends on the generated-sources
, do I have to manually specified the compiler includes?
推荐答案
自动生成插件的插件通常不会自动处理,方法是将其输出目录(按惯例类似于target/generated-sources/<tool>
)添加为POM的源目录,以便稍后在编译时将其包含阶段.
Nothing automatic, plugins generating source code typically handle that by adding their output directory (something like target/generated-sources/<tool>
by convention) as source directory to the POM so that it will be included later during the compile phase.
一些实施不完善的插件无法为您做到这一点,您必须自己添加目录,例如使用构建帮助器Maven插件.
Some less well implemented plugins don't do that for you and you have to add the directory yourself, for example using the Build Helper Maven Plugin.
并且由于您没有提供任何POM代码段,任何链接,所以我无话可说.
And since you didn't provide any POM snippet, any link, I can't say anything more.
正如我所说,生成的源通常作为源目录添加和编译,因此可以在测试类路径上使用,而无需执行任何操作.
As I said, generated sources are usually added as source directory and compiled and are thus available on the test classpath without you having to do anything.
这篇关于Maven不能在生成源中添加文件以进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!