'gradle classes are not generated

I am trying to convert my project to gradle and unable to get the class files generated under build folder. Here is the build.gradle file:

import org.gradle.internal.os.OperatingSystem;
apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

sourceSets {
    main {
        java {                  
            srcDirs = ["abc/def/"]
            include('include/Constants.java')                                   
            }
        }
}

task initial(type: Exec) {
    doFirst {
    println 'Started compiling constants'
  }
  if(OperatingSystem.current().isWindows()) { 
    println 'Compiling on windows'
    //Run some bash script here
  }
  else {
    print 'Compiling on unix'
    //Run some shell script here
  }
  doLast {
    println 'Finish compiling constants'
  }
}

jar {
    baseName = 'output' 
}

dependencies {
    compile files('../lib/log4j/log4j.jar')     
    compile files('../lib/findbugs/findbugs.jar')   
    compile files('../lib/guava/guava-19.0.jar')    
}

When i do gradle build, it says successfull, but see no classes generated under build folder. Any help?



Solution 1:[1]

Fixed it after some debugging. The issue was the include after the srcDirs did not work as the path was one level higher than the path defined in srcDirs.

Solution 2:[2]

I had a similar issue the other day, it was not generating the compiled classes when I run the build on IntelliJ or even on the terminal.

After trying a lot of things what solved the issue was deleting the .gradle directory and running again a ./gradlew clean build.

It was a weird one, but I hope it might help to someone having the same issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jony
Solution 2 Maximiliano De Lorenzo