IntelliJ 2016 has just been released, with improved support for Gradle: Each SourceSet is now mapped to a different module, which finally allows IntelliJ to understand our dependencies correctly.
Unfortunately, this means that the IDEA plugin doesn’t reflect IntelliJ’s internal model anymore: IdeaModule’s properties don’t match the new internal model of the IDE and therefore seems to be ignored in the new version. For that reason, marking folders as test sources or generated sources is not possible anymore, for example.
This seems like a problem Jetbrains cannot possibly resolve themselves. Is updating the idea plugin on the roadmap? Do you have an ETA?
we’re aware of this but havn’t scheduled any work on this at the moment and therefore can’t provide a ETA at the moment. We’ll let you know when we have more details on this.
I need to be able to mark the integration test SourceSet as test sources and all folders containing generated sources as generated sources. Without any help from the plugin, IDEA has no idea what the additional SourceSets actually are and cannot mark them correctly.
Previously I also used the idea plugin to work around bugs by manipulation the XML of the generated *.iml files, but those workarounds don’t seem to be necessary anymore.
From my experience, all features described here work fine with the synchronization from within IDEA, without having Gradle to generate any project and module files. e.g.
The exception to this are all methods that directly manipulate the XML (e.g. whenMerged). I didn’t try all of them, though. But adding generated sources, more test directories, things to IDEA’s library path etc. are all things I do regularily.
It did work before 2016, but now IntelliJ ignores those properties, since the original assumption (Gradle subproject = IDEA module) is no longer true. Since the upgrade, IntelliJ creates one module per SourceSet, so it cannot use the IdeaModule properties anymore.
Ouch! That’s a huge regression on IDEA’s side. I already was scared when I first saw what IDEA does since 2016.1. So did they actually completely break Gradle integration?
If this actually no longer works, JetBrains managed to degrade the Gradle integrations’s usefulness from 10 to 0 with a single update → report this to JetBrains.
BTW, for generated sources, I never used sourceDirs. Adding the directories to the main SourceSet was always enough, IDEA picked this up.
I’ll have to investigate. I was wondering WTF they did when I first saw the new way of syncing, but didn’t think of the implications (yet). I don’t want to rewrite all my builds (and probably, I don’t have to – they’re usually quite thoughtful at JetBrains).
Edit:testSourceDirs+=... still works fine, as does scopes.PROVIDED.plus.... It can’t be that bad.
Actually, the change on their side makes a lot of sense. The fact that every SourceSet is now its own module means that IntelliJ can finally understand the dependencies of different configurations correctly.
For example, we have test dependencies between different submodules. When the tests of subproject B depend on the tests of subproject A, IntelliJ now finally understands that and adds the test dependencies of subproject A as test dependencies of subproject B. Getting IntelliJ to grasp that required ugly XML hacks in the past. (Set exported=true for all dependencies, which means that IntelliJ will now also erroneously think that the test dependencies of A are dependencies of the main sources of B.)
We also have cases where the tests of subproject A depend on the main sources of subproject B, which in turn depend on the main sources of subproject A. IntelliJ always thought that this was a circular dependency and couldn’t be convinced that this is actually OK.
Especially large, complicated projects like ours benefit a lot from that change and it makes a lot more sense than the previous behavior. OTOH, it means that the integration is now broken. Which is why I both filed a bug in the IntelliJ bug tracker and started a thread here: Both sides need to work on this.
It didn’t when I tested. Did you remove the old .idea directory and all *.iml files and re-import the Gradle project?
Yes, generally, the new way of syncing seems at least just fine. I have no complex project at hand currently, but I’ve gotten over the first shock and everything seems still fine.
No, it just worked. All my old build files just work, including testSourceDirs and the old custom provided scopes (didn’t migrate yet to 2.12).
I just started out using IDEA and am bitten by this:
Why does IDEA create a module with content-root myModule/, 1 with myModule/src/main and one with myModule/src/test.
The problem for me is that I have IDEA using the “freebuilder” annotation process generating into myModule/build/generated-source
I cannot select mark that folder as source-folder inside IDEA though, since the “myModule” - module content root excludes “build”. Is there a way around this?
Raffael, gradle plugin for IDEA is still useful for me. I generate IDEA’s run configurations from gradle. Without it I’ll have to find/parse xml files directly which I do not want to do. It still can do many thing, that default IDEA’s import can’t do.
In general I do not want to wait until JetBrains folks made things right, I want to be able to do work/correct myself. With this plugin I can.
But it definitely gone outdated long ago. It does not generate IDEA’s directory-based projects (which is default now) but deprecated *.ipr-based.
And now IDEA have this hierarchical modules, which I think they made specially for better gradle support.
I wish gradle plugin for IDEA to generate dir-based projects with support for hierarchical modules and that I could still add my patches to the configuration of which IDEA’s importer will never be aware.