1

I'm using Intellij and a coworker is using Eclipse. There is a datamodel project that most components depend on that has all the JPA code.

One of datamodel dependencies is utils. In utils there are generated sources. My coworker in Eclipse, adds the target/generated-sources of utils to the build path and everything builds and runs fine within Eclipse.

In Intellij, when I go to Project Structure, do I need to go to utils and add the target/generated-sources of utils as a Source folder to be equivalent?

Or do I need to add that module as a dependency?

Edit: In 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>
Crystal
  • 28,460
  • 62
  • 219
  • 393
  • How are those dependencies managed? For example, using maven to define the dependencies would automatically include the utils.jar so the project becomes IDE agnostic. If the project is managed manually through an IDE to get things to compile, then how are projects accurately deployed with all of their dependencies? – Andrew S Aug 28 '17 at 18:46
  • `utils` is a dependency within maven for `datamodel`. – Crystal Aug 28 '17 at 18:49
  • Then datamodel.jar should be a dependency within the other project. Transitive dependencies will also include utils.jar (unless it's specifically marked to exclude or flagged as provided). – Andrew S Aug 28 '17 at 18:52
  • Possible duplicate of [Unable to use Intellij with a generated sources folder](https://stackoverflow.com/questions/5170620/unable-to-use-intellij-with-a-generated-sources-folder) – Meo Aug 28 '17 at 19:43
  • Use `build-helper-maven-plugin` -> https://stackoverflow.com/a/5171035/685796 – Meo Aug 28 '17 at 19:44

2 Answers2

2

You could use utils which were built by your coworker as a dependency. But if you ever want to change sources of utils then you should fix its pom.xml by adding:

<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 supports the plugin and the generated-sources folder will be marked as Source folder after clicking on Reimport.

Meo
  • 12,020
  • 7
  • 45
  • 52
-1

That depends if the project you build locally actually generates the sources. One instance Intellij picked up the generated sources automatically for me. If Intellij does not do it automatically then you should it as a source folder manually.

If your project doesn't generate the sources then you should add them as a dependency.

So in your case the decision is already made in the utils dependency/project. Does the utils dependency/project generate the sources or does it contain the sources?

  • The utils project generates the sources. – Crystal Aug 28 '17 at 19:02
  • Then you should add the project as a dependency in maven. The creator of the dependency has already decided how to package the dependency. Usually in a maven environment the packages of your company are already installed on your artifact repository. The only thing you need to do is define the dependency in your own pom to include it in your project. If the dependency is not in the company repository you need the source code of the project and generate and compile the sources with maven. This is usually done by the command: maven clean install – Henry Hoendervangers Aug 28 '17 at 19:22
  • And consider installing it in your company repository if other projects also need it. This is usually done by the command: maven clean deploy – Henry Hoendervangers Aug 28 '17 at 19:27
  • what i'm trying to say is that you probably don't need the generated sources but you can use the artifact instead – Henry Hoendervangers Aug 29 '17 at 05:45