Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ can't find generated sources when used in same module

I'm using annotation processors of Google's AutoFactory. I annotated SomeClass with @AutoFactory and referenced new SomeClassFactory().create() somewhere else in that same module.

Maven configuration:

I added the necessary dependency in Maven:

    <dependency>
        <groupId>com.google.auto.factory</groupId>
        <artifactId>auto-factory</artifactId>
        <version>1.0-beta2</version>
        <optional>true</optional>
    </dependency>

When running $ mvn clean compile I see that target/generated-sources/annotions/somepackage/SomeClassFactory is created and the module compiles without errors.

IntelliJ configuration:

  • Reimport all maven modules
  • Preferences -> Annotation Processors -> Enable annotation processing
  • Rebuild Project

This should be enough in my version of IDEA (v14.1.4) if my understanding is correct.

Compiler Preferences Project Structure

I also performed the following steps:

  • Verified that generated-sources folder is added as a source in Project Structure
  • Verified that Maven preference Generated sources folders is set to Detect automatically
  • Verified that source is actually generated upon Rebuild (deleted target folder first to be sure it's generated by IntelliJ)
  • Try to disable Exclude output paths in Project Structure, as suggested by @tilpner
  • Invalidate caches and restart
  • Delete .idea folder and .iml files
  • Experiment with different settings for Phase to be used for folders update in Preferences -> Maven -> Importing

Problem:

After performing all these steps, the generated class doesn't show up in the project explorer. In fact, the entire target directory is nowhere to be seen. Compilation fails with cannot find symbol: SomeClassFactory and new SomeClassFactory().create() is marked in red in the editor, while Maven generates and compiles without any problems.

I'm out of options myself and any help or suggestions would be very welcome!

Update: when I comment the code that causes the compilation error, IntelliJ prints this warning in the compilation messages: Warning:Output path /Users/.../target/generated-sources/annotations intersects with a source root. Only files that were created by build will be cleaned.

like image 500
Rolf W. Avatar asked Oct 21 '15 13:10

Rolf W.


People also ask

How do I add generated sources in IntelliJ?

You can just change the project structure to add that folder as a "source" directory. Project Structure → Modules → Click the generated-sources folder and make it a sources folder.

How do I change the source folder in IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Modules. Select the necessary module and open the Sources tab. next to Source Folders or Test Source Folders. Specify the package prefix and click OK.

How do I change directory in IntelliJ module?

Select the top-level directory in the Project tool window and press Alt+Insert or select New | Module from the context menu. The New Module wizard opens. From the list on the left, select a module type.


1 Answers

I got help from Jetbrains support and the problem turned out to be a preference for excluded files. There are two places where these are configured:

Please check that folders/files are not excluded in Preferences > Build, Execution, Deployment > Compiler > Excludes and the file/folder pattern in not listed in Preferences > Editor > File Types -> Ignored files and folders

In my case target was included in the ignored files and folders list in Editor > File Types.

Then there was still a compilation issue, which I solved by throwing away the IDEA project files and creating the project again.

like image 63
Rolf W. Avatar answered Sep 18 '22 05:09

Rolf W.