Gradle 在信息级别的HelloTask的任务操作的开始和结束处添加日志记录语句

Gradle 在信息级别的HelloTask的任务操作的开始和结束处添加日志记录语句,gradle,Gradle,Gradle 6.6.1 任务: 在信息级别的HelloTask任务操作的开始和结束处添加日志记录语句 我的解决方案: task doBefore(type: DoBefore) task hello(type: HelloTask) class DoBefore extends DefaultTask { @TaskAction void doBefore() { logger.info('Before.') } } class HelloTa

Gradle 6.6.1

任务:

  • 在信息级别的HelloTask任务操作的开始和结束处添加日志记录语句
  • 我的解决方案:

    task doBefore(type: DoBefore)
    
    task hello(type: HelloTask)
    
    
    class DoBefore extends DefaultTask {
        @TaskAction
        void doBefore() {
            logger.info('Before.')
        }
    }
    
    
    class HelloTask extends DefaultTask {
        doBefore = DoBefore()
    
        @TaskAction
        void doAction() {
        dependsOn doBefore
            println 'Hello World'
        }
    }
    
    不工作:

    $ gradle hello
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/home/michael/Documents/GradleUdacity/ud867-master/1.17-Exercise-InvestigateLogging/build.gradle' line: 57
    
    * What went wrong:
    Could not compile build file '/home/michael/Documents/GradleUdacity/ud867-master/1.17-Exercise-InvestigateLogging/build.gradle'.
    > startup failed:
      build file '/home/michael/Documents/GradleUdacity/ud867-master/1.17-Exercise-InvestigateLogging/build.gradle': 57: unexpected token: doBefore @ line 57, column 5.
             doBefore = DoBefore()
             ^
      
      1 error
    
    
    * 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
    

    我想,我什么都做错了。这不一定与错误有关。但我想,我还没有领会这项任务的意思。

    这是某种课程的结果吗?您是否已经了解了
    doFirst
    doLast
    $ gradle hello
    
    FAILURE: Build failed with an exception.
    
    * Where:
    Build file '/home/michael/Documents/GradleUdacity/ud867-master/1.17-Exercise-InvestigateLogging/build.gradle' line: 57
    
    * What went wrong:
    Could not compile build file '/home/michael/Documents/GradleUdacity/ud867-master/1.17-Exercise-InvestigateLogging/build.gradle'.
    > startup failed:
      build file '/home/michael/Documents/GradleUdacity/ud867-master/1.17-Exercise-InvestigateLogging/build.gradle': 57: unexpected token: doBefore @ line 57, column 5.
             doBefore = DoBefore()
             ^
      
      1 error
    
    
    * 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