我有以下简单的build.gradle文件:
apply plugin: 'java'
task foo(type: JavaExec) {
main = 'gradletest2.Main'
classpath = runtimeClasspath
}
在执行时会导致产生以下错误:
C:\Users\J\Documents\Development\eclipse-photon\gradletest2>gradle foo
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\J\Documents\Development\eclipse-photon\gradletest2\build.gradle' line: 17
* What went wrong:
A problem occurred evaluating root project 'gradletest2'.
> Could not get unknown property 'runtimeClasspath' for task ':foo' of type org.gradle.api.tasks.JavaExec.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
BTW Main很简单:
package gradletest2;
public class Main {
public static void main(String[] args) {
System.out.println("gradletest2");
}
}
为什么会出现此错误?我正在https://youtu.be/OFUEb7pLLXw?t=2043上观看有关YT的官方gradle教程视频,但是很遗憾,它已经很老了,所以我想知道这是否现在是不正确的语法。 提前致谢。
我正在使用gradle 4.10.2。
答案 0 :(得分:3)
runtimeClasspath
是主sourceSet的属性。正确的语法是
classpath = sourceSets.main.runtimeClasspath