Recently, I found all my gradle projects in Idea import separated modules for main and test. The modules look like this:
As you can see, there is a "main" module which content root is the src/main and includes only main classes and resources, and there is a "test" module as well. The modules just don't look right. Is this an expected behavior?
The Idea is Intellij Idea 2016.1.1
and the gradle is 2.11
Here is the content of build.gradle
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: "jacoco"
version = getVersion()
sourceCompatibility = 1.8
targetCompatibility = 1.8
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
}
test {
resources {
srcDir 'src/test/data'
}
compileClasspath += configurations.provided
}
}
processResources {
filter { String line -> line.replace("{version}", getVersion()) }
}
processTestResources {
filter { String line -> line.replace("{version}", getVersion()) }
}
idea {
module {
scopes.PROVIDED.plus += [configurations.provided]
}
}
repositories {
mavenCentral()
}
If you have some custom plugins that require you to import your project from the IntelliJ IDEA model, press Ctrl+Shift+A and search for the Project from Existing Sources action. In the dialog that opens, select a directory containing a Gradle project and click OK. IntelliJ IDEA opens and syncs the project in the IDE.
In IntelliJ IDEA, a module is an essential part of any project – it's created automatically together with a project. Projects can contain multiple modules – you can add new modules, group them, and unload the modules you don't need at the moment.
UPDATE:
It appears Jetbrains removed the checkbox I was referring to since I posted this. galcyurio's answer looks like the correct way to disable this functionality in current builds.
Original Answer:
You can turn this off in Gradle Settings. Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle: uncheck create separate modules per source set.
I had to turn it off as it was causing build failures because Make was only pulling in the main source set. This is likely a bug in Intellij because gradle can still build the projects just fine.
I have the same effect which is not what I expected especially as IntelliJ 14 Ultimate behaves completely different on the same project.
This is the new behavior of IntelliJ introduced with version 2016.1 to handle complex Gradle projects (which never worked completely before when you introduced new source sets).
It looks a little bit strange but works (better than before). And you can see the dependencies for each source set in the gradle project window now.
See also What's New in IntelliJ IDEA 2016.1 and Gradle Goodness: Source Sets As IntelliJ IDEA Modules.
I looked for intellij's settings here and there, but couldn't find options. So I checked the source of the community version on GitHub. This option is deprecated. Not sure, but it seems to be set invisible.
This setting is deprecated and remains only for troubleshooting since it's not fully compatible with Gradle's model. Please consider restoring it to the default (checked)
See lines 20-22 of this file.
In my case, I cannot find the option which 'Alex Spence' mentioned.
You can turn this off in Gradle Settings. Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle: uncheck create separate modules per source set.
I searched about that option, fortunately a lot of other answers showed me where is that option.
We can uncheck this option when we import or create module and import project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With