我正在使用 Intellij,一位同事正在使用 Eclipse。大多数组件都依赖一个 datamodel
项目,该项目包含所有 JPA 代码。
datamodel
依赖项之一是 utils
。在utils
中有生成的源。我在 Eclipse 中的同事将 utils 的目标/生成源添加到构建路径中,并且一切都在 Eclipse 中构建并运行良好。
在 Intellij 中,当我转到“项目结构”时,是否需要转到 utils
并将 utils
的目标/生成源添加为 Source
文件夹是否等效?
或者我需要将该模块添加为依赖项吗?
编辑: 在utils pom中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="target/generated-sources" />
<exec executable="protoc">
<arg value="--java_out=target/generated-sources" />
<arg value="src/main/resources/utilities.proto" />
</exec>
</tasks>
<sourceRoot>target/generated-sources</sourceRoot>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
最佳答案
您可以使用由您的同事构建的 utils
作为依赖项。
但如果您想更改 utils
的源,那么您应该通过添加以下内容来修复其 pom.xml:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>test</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/generated-sources</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
IntelliJ 支持该插件,点击Reimport
后, generated-sources
文件夹将被标记为 Source
文件夹。
关于java - 如何将依赖项目的生成源添加到构建路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45925353/