【发布时间】:2021-02-07 16:31:44
【问题描述】:
当我使用 Gradle 6.7.1 运行 gradle init 时,会构建一个包含 mainClass 变量的 gradle.build 文件。然而这需要mainClassName,如果使用mainClass,它会失败。请参阅下面的详细信息。
为什么gradle init 会生成不可用的代码?
gradle.build的相关部分:
application {
// Define the main class for the application.
mainClassName = 'com.mycompany.MyFileKt'
}
jar {
manifest {
attributes 'Main-Class': mainClassName
}
from {
configurations.compile.collect {
it.isDirectory() ? it : zipTree(it)
}
}
}
如果我们将两个出现的mainClassName 替换为mainClass,则会出现错误消息。
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/joshua/dev/multicloud/app/build.gradle' line: 47
* What went wrong:
A problem occurred evaluating project ':app'.
> Could not get unknown property 'mainClass' for object of type org.gradle.api.java.archives.internal.DefaultManifest.
【问题讨论】: