Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refreshing gradle in IntelliJ causes source folder structure to change

When I run refresh gradle in IntelliJ IDEA, my main folder is set to be the source root, but "java", which is my actual source root, is unmarked.

I have to change this manually every time after I do gradle refresh.

Do you know what the relevant gradle setting is?

Can it be in a common gradle file?

Should I change the main folder to be the source root?

enter image description here

enter image description here

How can I know where is the common gradle I might inherit from? How can I override this in my local build.gradle?

My build.gradle:

apply plugin: 'java'
apply plugin: 'application'

sourceCompatibility = 1.8
version = '1.0'

repositories {
    mavenCentral()
}

dependencies {
//
//    configurations.all*.exclude(group: 'com.sun.jersey', module: 'jersey-bundle')
//    configurations.all*.exclude(group: 'com.fasterxml.jackson.core', module:'jackson-databind')


    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'

    compile 'com.google.inject:guice:4.0-beta5'
    compile 'com.sun.jersey:jersey-core:1.18.3'
    compile 'com.sun.jersey:jersey-client:1.18.3'
    compile 'com.sun.jersey:jersey-json:1.18.3'
    compile 'com.sun.jersey.contribs:jersey-apache-client:1.18.3'
    compile group: 'junit', name: 'junit', version: '4.11'
    compile 'com.vividsolutions:jts:1.13'
    compile 'net.sf.opencsv:opencsv:2.3'
    compile 'com.googlecode.json-simple:json-simple:1.1'
    compile 'com.google.guava:guava:18.0'

    //testCompile group: 'junit', name: 'junit', version: '4.11'
}


sourceSets {
    main {
        java {
            srcDirs = ['src/main']
        }
    }

    test {
        java {
            srcDirs = ['src/main']
        }
    }
}


test {
    testLogging {
// Show that tests are run in the command-line output
        events 'started', 'passed'
    }
}


task run_BaselineGenerator(type: JavaExec) {
    classpath sourceSets.main.runtimeClasspath
    main = "com.waze.routing.automation.runners.BaselineGenerator"
}
like image 364
Elad Benda Avatar asked Feb 22 '15 12:02

Elad Benda


People also ask

What does Gradle refresh do in IntelliJ?

Clicking the refresh button in the gradle tool window does the following: On pressing this button, IntelliJ IDEA parses the project structure, and displays detected differences (if any) in the Gradle tool window. It essentially refreshes the project structure from any changes in gradle.

How do I refresh the Gradle cache in IntelliJ?

Pressing on the Refresh Gradle icon in the top right, Using the keyboard shortcut ⇧⌘I (macOS), or Ctrl+Shift+O (Windows/Linux).

How do I change the source directory in IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Project Settings | Modules. Select the necessary module and then open the Sources tab in the right-hand part of the dialog. Click Add Content Root and specify the folder that you want to add as a new content root.


1 Answers

Your sourceSets look incorrect to me. I would try:

sourceSets {
    main {
        java {
            srcDirs = ['src/main/java']
        }
    }

    test {
        java {
            srcDirs = ['src/test/java']
        }
    }
}
like image 89
vikingsteve Avatar answered Oct 10 '22 08:10

vikingsteve