Sun*_*Wei 16 code-generation thrift maven
我使用Apache Thrift来生成代码target/generated-sources.
Thrift编译器生成一个名为的目录gen-java,其中包含所有Java代码.当我执行时mvn compile,代码生成正确target/generated-source/gen-java,但在编译阶段,它抱怨无法找到定义的类gen-java.
据我了解,Maven 2自动添加生成的源,是吗?
如果我的测试代码也依赖于generated-sources,我是否必须手动指定编译器包括?
Pas*_*ent 18
在我的理解中,maven 2自动添加生成的源,是吗?
没有什么是自动的,生成源代码的插件通常通过将它们的输出目录(类似于target/generated-sources/<tool>惯例)作为源目录添加到POM来处理它,以便稍后在编译阶段将其包括在内.
一些不太好实现的插件不会为您执行此操作,您必须自己添加目录,例如使用Build Helper Maven插件.
既然你没有提供任何POM片段,任何链接,我不能再说了什么.
如果我的测试代码也依赖于生成的源代码,我是否必须手动指定编译器包括?
正如我所说,生成的源通常作为源目录添加并编译,因此可以在测试类路径中使用,而无需执行任何操作.
生成的源不会自动编译或打包。然而,某些 IDE(即 IntelliJ)会将它们显示为源文件夹。
要使生成的源对 Maven 可见,请向您的节点添加一个add-source-step :build/pluginspom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/gen-java</source><!-- adjust folder name to your needs -->
</sources>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)