46

Recently, I found all my gradle projects in Idea import separated modules for main and test. The modules look like this:

enter image description here

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()
}
0

3 Answers 3

36

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.

2
  • 3
    After 4 days of searching to resolve Querydsl error which generated classes can't find beans and vice-versa, this solves the problem. Thanks.
    – cmlonder
    Aug 9, 2017 at 14:35
  • 9
    Seems like there's no more create separate modules per source set option in IDEA 2019.2 Aug 7, 2019 at 20:29
13

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.

2
  • Thank you for the links. But how do I Add Framework Support with the new changes? Do I have to add Spring facet on both main and test modules? May 4, 2016 at 10:29
  • What if I have circular dependencies as a result of this?
    – Jack Cole
    Oct 2, 2019 at 0:50
12

Above 2019.2

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.


Environment

  • IntelliJ IDEA 2017.2 (Build #IU-172.3317.76, built on July 15, 2017)
  • Windows 10
  • Gradle project

Trouble shooting

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.

Solution

We can uncheck this option when we import or create module and import project.

when import project

  • File -> New -> Project from existing sources... -> select file -> Gradle -> uncheck create separate modules per source set
  • Welcome page -> Import project -> select file -> Gradle -> uncheck create separate modules per source set

when import module

  • Project Structure -> Add -> import module -> select file -> Gradle -> uncheck create separate modules per source set

when create new module

  • You can also uncheck this option when you create new module.
2
  • This checkbox doesn't exist anymore, anywhere, in IntelliJ IDEA 2019.2... Does someone have a solution working with this version ?
    – Eria
    Sep 13, 2019 at 11:28
  • 2
    @Eria there is a workaround here youtrack.jetbrains.com/issue/IDEA-222172
    – Aaron
    Oct 16, 2019 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.