StopExecutionException

StopExecutionException

我正在尝试在我的Android gradle文件中添加“thow StopExecutionException”:

apply plugin: 'com.android.library'
task exportJar(type: Copy) {

    def classesJar = file("build/intermediatess/bundles/release/classes.jar")
    if (classesJar.exists()) {
       //some code
    } else {
        **throw StopExecutionException**(classesJar.getPath() + " doesn't exist");
    }
}

我使用现有的解决方案:

Recommended way to stop a Gradle build

但是gradle不会重新识别StopExecutionException和其他任何异常。

我该怎么办?应用某种插件?添加classpath依赖关系?

最佳答案

您忘记在异常(exception)之前添加new。您需要像普通的Java异常一样抛出它:

throw new StopExecutionException(classesJar.getPath() + " doesn't exist");

09-08 08:19