英文:
Gradle init project not able to add dependencies to "app" subproject
问题
我使用Gradle 8.1.1创建了一个新项目,选择了应用程序(2)、Java(3)、没有多个子项目、Groovy DSL、JUnit 5、相同的项目和源包名称以及Java 11。
我将Apache Commons添加到app/build.gradle,并希望在App.java中调用StringUtils,但失败了。起初我以为是VS Code有问题,但运行./gradlew build
也失败了,错误如下:
gradle-basic-structure-dep-error\app\src\main\java\gradle\basic\structure\dep\error\App.java:10: error: incompatible types: boolean cannot be converted to String
return StringUtils.isBlank(" ");
^
1 error
FAILURE: Build failed with an exception.
这是完整的示例链接:https://github.com/cwansart/gradle-basic-structure-dep-error
为什么会失败?这可能是生成的代码中的错误吗?
英文:
I created a new Gradle 8.1.1 project with gradle init
chosing the options application (2), Java (3), no multiple subprojects, Groovy DSL, JUnit 5,the same project and source package name and Java 11.
I added Apache Commons to app/build.gradle and wanted called StringUtils in App.java but it failed. I first thought VS Code had an issue, but running ./gradlew build
fails also with:
gradle-basic-structure-dep-error\app\src\main\java\gradle\basic\structure\dep\error\App.java:10: error: incompatible types: boolean cannot be converted to String
return StringUtils.isBlank(" ");
^
1 error
FAILURE: Build failed with an exception.
Here is the full example: https://github.com/cwansart/gradle-basic-structure-dep-error
Why is it failing? Might this be an error in the generated code?
答案1
得分: 1
以下是已翻译的内容:
因为 getGreeting()
的返回类型是 String
,而 StringUtils.isBlank(" ")
的返回类型是 boolean
。
所以你应该像下面这样更改返回类型:
public boolean getGreeting() {
return StringUtils.isBlank(" ");
}
此外,你应该使用像Intelij或Eclipse这样的IDE来编写Java代码。它会为你突出显示和报告这种类型的错误。
英文:
It's because the return type of getGreeting()
is String
, and return type of StringUtils.isBlank(" ")
is a boolean
.
So you should change the return type like below
public boolean getGreeting() {
return StringUtils.isBlank(" ");
}
Beside, you should write java code using IDE like Intelij or Eclipse. It will highlight and report this kind of error for you
答案2
得分: 0
To clarify the issue: in VS Code the imports were marked red and not found, regardless of the error I did mention by Jeremie.
I tried it on a different computer on which it worked. I tried it again on my working machine in a new profile with a clean checkout and it worked again. It seems that the Java or Gradle VSCode plugin had an issue, I guess?
英文:
To clarify the issue: in VS Code the imports were marked red and not find, regardless of the error I did mentioned by Jeremie.
I tried it on a different computer on which it worked. I tried it again on my working machine in a new profile with a clean checkout and it worked again. It seems that the Java or Gradle VSCode plugin had an issue, I guess?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论