Set up gradle source path includes with intellij source path?

We have a project folder in the following manner:


 --com

  --....

 --config

 build.gradle

 ...  

The source code is under “com” folder. In the Intellij, I have subfolder “com” as source folder and set the package as “com”. In the gradle script, I have

sourceSets {
    main {
        java {
            srcDir '.'
            include 'com/**'
          }
    }

Neither Gradle idea plugin or Intellij gradle plugin can effectively translate this into a proper intellij setting. It will map the “.” folder into the source and I ended up with huge amount of junk in the build path (*.class) of the intellij module, because it include the “build” subfolder as the source.

If I manually correct setting, every (sometimes automatic) refresh of the plugin will wash out my change. This gets annoying enough, so I have to disable the gradle plugin and manually output all the dependencies into a subfolder “libs”, and include all jars in it into a module as dependencies manually. But this will not automatically connect the javadocs or sources.

task copyLibs(type: Copy, dependsOn: 'libsClean') {
        def libFiles = files(configurations.compile)
     from libFiles
    include '*.jar'
    into 'libs'
}

Is there any better way? Thanks.