java - 如何将依赖项目的生成源添加到构建路径?

标签 java eclipse intellij-idea

我正在使用 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/

相关文章:

java - 如何确定哪些 Eclipse 插件对菜单和工具栏有贡献并停止它们

spring-boot - Intellij IDEA 2018.2 缺少 Spring Boot 运行仪表板

java - 如何在 IntelliJ 中查看 Tomcat 生成的 Web 应用程序日志

tomcat - 如何判断MyEclipse如何部署Tomcat webapp

java - MapReduce 作业无法从 HBase 读取(抛出 java.lang.NoClassDefFoundError)

java - 在 gradle 中运行单个 junit 测试通过但在运行整个测试时失败

eclipse - 从 Eclipse 启动 JBoss 时有什么加速的技巧吗?

java - ConstraintViolationException 不能同时适用于 DTO 和 MODEL 类

java - JUnit 测试沙箱没有网络和文件访问权限?

eclipse - Maven eclipse 插件,排除传递依赖