【问题标题】:some Gradle command-line options not working一些 Gradle 命令行选项不起作用
【发布时间】:2021-08-30 06:22:28
【问题描述】:

我有以下代码:

task helloGradle {
   println 'Hello Gradle - This is your first script'
}

task failedTask {
   assert 1 == 2
}

task test(dependsOn:helloGradle) {
   println 'Test case executed'
}

当 gradle 从命令行 (Ubuntu) 执行第二个任务时,我希望执行失败并停止,它确实如此。但是,当我使用 --continue 选项以便它继续执行最后一个任务('test')时,无论第二个任务的执行是否失败,它仍然会卡在失败的任务上并且不再继续。

我在命令行(从我的项目目录中)发出的命令如下:

gradle failedTask test --continue

即使我尝试其他命令行选项,例如:

gradle --gui

它没有像我预期的那样启动 Gradle GUI,并提供了 - 未知的命令行选项“--gui”。

我做错了吗?任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: gradle


    【解决方案1】:

    根据the official doc,Gradle 构建分为三个阶段:初始化配置执行。您的printlnassert 语句都处于配置阶段,而不是执行阶段。这就是为什么--continue 没有按预期工作的原因。

    您可以查看官方文档中的示例代码:

    println 'This is executed during the configuration phase.'
    
    tasks.register('configured') {
        println 'This is also executed during the configuration phase, because :configured is used in the build.'
    }
    
    tasks.register('test') {
        doLast {
            println 'This is executed during the execution phase.'
        }
    }
    
    tasks.register('testBoth') {
        doFirst {
            println 'This is executed first during the execution phase.'
        }
        doLast {
            println 'This is executed last during the execution phase.'
        }
        println 'This is executed during the configuration phase as well, because :testBoth is used in the build.'
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-01
      • 1970-01-01
      • 2016-02-06
      • 1970-01-01
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      相关资源
      最近更新 更多