gradle - 如何在 Gradle 中执行任务?

标签 gradle build.gradle

我有以下项目结构:

  • 应用
  • build.gradle
  • build.gradle
  • settings.gradle

  • 应用程序/build.gradle:
    apply plugin: 'java'
    

    设置.gradle:
    include ':application'
    

    构建.gradle:
    task custom << {
      project.tasks.getByName("build").execute()
    }
    

    所以我想在任务“custom”中执行任务“build”。
    但是当我运行“gradle custom”时,结果是:
    :custom FAILED
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/tmp/test/build.gradle' line: 3
    
    * What went wrong:
    Execution failed for task ':custom'.
    > Task with name 'build' not found in root project 'test'.
    
    * Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    
    BUILD FAILED
    
    Total time: 1.183 secs
    

    我如何在任务“custom”中执行任务“build”?

    最佳答案

    你不能。任务执行是声明性的,而不是强制性的。任务相互依赖,它们不相互执行。 (此外,由于您没有在根构建脚本中应用 Java(基础)插件,因此根项目没有 build 任务。)

    关于gradle - 如何在 Gradle 中执行任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16662975/

    相关文章:

    Android build java.lang.NullPointerException (无错误信息) org.gradle.api.ProjectConfigurationException BUILD FAILED

    android - gradle.build 错误 (28,0) : Gradle DSL method not found: 'apply()'

    android - Gradle 构建过程失败

    梯度错误: No method add() found for arguments

    android - ViewPagerIndicator 与 Gradle 和 Android Studio 的依赖关系

    gradle - 我在哪里可以把我的自定义任务类放在 Gradle 中

    android - IntelliJ for Android Gradle 项目中的依赖项

    gradle - gradlew包装器更新到新版本错误,您具有旧版本

    gradle - Gradle 插件在哪里?

    android - 在 com.android.build.gradle.AppExtension_Decorated 上找不到属性 'xxxx'