question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Project generates incorrect IntelliJ source roots for Kotlin modules

See original GitHub issue

After running buck project on a project that has kotlin (a project with rules such as kotlin_library, android_library with language set to Kotlin, etc), the source roots of those modules are not made correctly in IntelliJ.

Here are a couple examples: image Note how the app directory is marked as the source root instead of src/main/java which is where the packages actually begin.

image And here, the kotlin-android module is the source root instead of src/main/java

Both of these examples could be src/main/kotlin depending on your naming conventions and/or use of mixed sources.

This causes the IDE to behave incorrectly when refactoring, importing those classes, and even when defining the package of that module.

If any of these modules are turned into pure java modules, they look correct: image

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:8
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
kageiitcommented, Jun 21, 2018

Alternatively, one can apply this patch to buck to have buck project respect source roots correctly without having to post process. Its a similar approach, but happens inside the project command itself

https://gist.github.com/kageiit/4e48964cb6d9382737b96c21e1adf730

1reaction
christiandeangecommented, Jun 21, 2018

For those looking for a quick fix, I’ve written up a python script that post-processes .iml files after buck project has generated them, and touches up the folder definitions to correct them. We use this internally at Square and it seems to cover all the use cases we have for misconfigured modules.

If you’re using okbuck, append this to your buck wrapper after running BUCK_BINARY to invoke the script automatically:

if [[ $? == 0 && "project" == $1 ]]; then
    python $SCRIPT_DIR/scripts/fix_sources.py -p $SCRIPT_DIR
fi
Read more comments on GitHub >

github_iconTop Results From Across the Web

Content roots | IntelliJ IDEA Documentation - JetBrains
From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Project Settings | Modules. Select the necessary module and then open...
Read more >
support "generated sources" flag for `kotlin-source` module root
The Kotlin source root may not have "for generated sources" property. Project Structure dialog does not suggest it, Gradle import does not set...
Read more >
Import Project from Existing Sources - JetBrains YouTrack
Import Project from Existing Sources: source roots and module roots are incorrectly detected ; Project, IntelliJ IDEA ; Priority, Major M ; Type,...
Read more >
Gradle + IDE integration: on creating source roots from Project ...
Gradle + IDE integration: on creating source roots from Project tree IDEA creates incorrect settings ... Prepare Gradle-based project with non-JVM Kotlin plugin....
Read more >
Module compiles, but editor shows compilation issues
Try invalidating your caches and restarting IDEA (File > Invalidate Cache). Wait for IDEA to re-index your project (Status indicator on lower ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found