gradle - 如何在gradle buildSrc类中使用Logger?

标签 gradle

所以,当我做幼稚的事情,只是使用:

logger.info("something")

我得到:
<myfile>.groovy: 52: Apparent variable 'logger' was found in a
static scope but doesn't refer to a local variable, static field or class.
Possible causes:
You attempted to reference a variable in the binding or an
instance variable from a static context.
You misspelled a classname or statically imported field.
Please check the spelling.
You attempted to use a method 'logger' but left out brackets
in a place not allowed by the grammar.
   @ line 52, column 9.
       logger?.info("Resolving ${projectPath} to ${version}")

我尝试了许多变体,例如在构造函数中设置类变量:
static private log = Logging.getLogger(MyClass)

由于无法在静态范围内找到日志,因此失败了...

这有什么魔术?

最佳答案

Gradle User Guide, chapter 18说,您可以仅在buildSrc中使用SLF4j。我在类(class)上的@ Slf4j注释很幸运。例如:

import groovy.util.logging.Slf4j

@Slf4j
class YourClass {
      def logIt(){
          log.info 'This is logged in Gradle'
      }
}

关于gradle - 如何在gradle buildSrc类中使用Logger?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29156055/

相关文章:

android - 在 gradle 中重构 Maven block

将 Artifactory 发布到 Artifactory 时 Jenkins 出错

gradle - 从所有多项目Gradle构建依赖项生成CLASSPATH

android - 单击Cast Mini Controller时android应用崩溃

gradle - 在 Gradle processResources 期间扩展 application.yml 会产生 MissingPropertyException

android - Flutter 的 main.dart 文件在 Android Studio 中执行时卡在 "Syncing files to device Android SDK built for x86 64..."

c - Gradle:任务 ':linkMainExecutable' 执行失败

Jenkins + Gradle + Artifactory : Deploy only work once

android - 在gradle中包含播放服务时,所有com.android.libraries支持都必须使用相同版本

gradle - 如何修复 "The following classes needed for analysis were missing"