java gradle:跳过任务“:compileJava”,因为它没有源文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26634000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 10:17:08  来源:igfitidea点击:

gradle: Skipping task ':compileJava' as it has no source files

javabuildcompiler-errorsgradle

提问by roroco

i try gradle -d compileJavain 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 initand creating a "src/Ex.java".

gradle -d compileJava我的 try 项目尝试,并且 gradle 提出“跳过任务':compileJava',因为它没有源文件。”。更糟糕的是,我看不到 build/ 中创建的任何内容。我只通过运行gradle init和创建“src/Ex.java”来创建这个项目。

my question is:

我的问题是:

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

如何加载默认的“compileJava”或定义我的“compileJava”来修复这个警告。

回答by Peter Niederwieser

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

默认情况下,Java 源文件需要进入src/main/java(或src/test/java用于测试源)。相应地调整您的目录结构,或按如下方式重新配置源目录:

sourceSets {
    main {
        java {
            srcDirs = ["src"]
        }
    }
}

回答by fahmi aouissaoui

You can also change gradle version to 4.8 in

您还可以将 gradle 版本更改为 4.8

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

then do:

然后做:

./gradlew build