所以,当我做幼稚的事情,只是使用:
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/