Gradle Build没有找到Java源代码

时间:2017-06-07 08:45:30

标签: gradle build

我正在尝试按照Spring给出的Gradle的HelloWorld教程但是Build步骤不起作用 - 当我运行Gradle Build时,我只看到消息,NO-SOURCE:compileJava步骤。 我在另一个问题上看到你应该将sourceSets标签添加到gradle.build文件中。我也尝试了这个,它仍然没有找到我的Java源文件。

我按照说明组织了我的Java源代码 将代码放在目录结构中,

=> src-main-java-hello(" HelloWorld.java,Greeter.java")。

我正在使用Java8和Gradle 3.5

有人可以帮忙吗? - 这似乎是我必须遇到的一个非常基本的问题。

enter image description here

enter image description here

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:1)

您在srcDirs = ['src']中定义了build.gradle,但后来使用src/main/java作为源目录。由于src/main/java是(非常明智的)默认源目录,因此您可以一起删除sourceSets { ... }配置。

答案 1 :(得分:0)

问题是一个令人尴尬的陷阱!它与添加sourceSets配置无关......我的Java文件已经在Windows下使用Notepad ++保存为文本文档而不是Java源文件,难怪Gradle报告没有源文件!下面的屏幕截图显示了差异。

要在Notepad ++中保存文件时要避免此问题,您可以使用引号包装名称,也可以选择Type作为Java程序。

enter image description here enter image description here

当我改变它并运行gradle.build时,一切正常。