15

i try gradle -d compileJava in my try project, and gradle raise "Skipping task ':compileJava' as it has no source files.". the worse thing is that i can't see anything created in build/. i create this project only with running gradle init and creating a "src/Ex.java".

my question is:

How to load default "compileJava" or define my "compileJava" to fix this warning.

tim_yates
  • 167,322
  • 27
  • 342
  • 338
roroco
  • 439
  • 1
  • 6
  • 14
  • of course, please see [my try project](https://github.com/roroco/try_gradle) i have commented out them – roroco Oct 29 '14 at 15:32

2 Answers2

21

By default, Java source files need to go into src/main/java (or src/test/java for test sources). Either adapt your directory structure accordingly, or reconfigure the source directory as follows:

sourceSets {
    main {
        java {
            srcDirs = ["src"]
        }
    }
}
Peter Niederwieser
  • 121,412
  • 21
  • 324
  • 259
  • 4
    It's interesting that my file structure is actually correct, my java code **is** in `src/main/java`, but I have to add these lines to make `gradle build` work. – Searene May 16 '17 at 10:15
  • 1
    ``sourceSets.main.java.srcDirs = ["src"] `` also works – john k Jul 22 '21 at 17:42
1

You can also change gradle version to 4.8 in

gradle-wrapper.properties 
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-bin.zip

then do:

./gradlew build
THess
  • 1,003
  • 1
  • 13
  • 21