Showing posts with label logging. Show all posts
Showing posts with label logging. Show all posts

Thursday, 3 June 2021

Gradle Build : Project API Inbuilt properties

 One can use these properties given by gradle project api, within build.gradle file.

------------------------------Start of the File--------------------------

build.gradle

//project api properties
logger.info("Name of the project: ${project.name}")
logger.info(
"absolute path of the project: ${project.path}")
logger.info(
"description for the project: ${project.description}")
logger.info(
"directory containing the build script: ${project.projectDir}")
logger.info(
"build directory: ${project.buildDir}")
logger.info(
"${project.group}")
logger.info(
"${project.version}")

//The above properties - print same as below
//project api properties without project. prefix - implied by default
logger.info("Name of the project: ${name}")
logger.info("absolute path of the project: ${path}")
logger.info("description for the project: ${description}")
logger.info("directory containing the build script: ${projectDir}")
logger.info("build directory: ${buildDir}")
logger.info("${group}")
logger.info("${version}")
------------------------------End of the File--------------------------
Execution:
gradle -i build

-i for enabling logging for info level.
Output:
Name of the project: gradle-demo
absolute path of the project: :
description for the project: null
directory containing the build script: /Users/dinesh/IdeaProjects/gradle-demo
build directory: /Users/dinesh/IdeaProjects/gradle-demo/build

unspecified
Name of the project: gradle-demo
absolute path of the project: :
description for the project: null
directory containing the build script: /Users/dinesh/IdeaProjects/gradle-demo
build directory: /Users/dinesh/IdeaProjects/gradle-demo/build

unspecified

Gradle Logging Options: How to use logger in gradle build files?

 By default, there are no logs printed, because logging is disabled by default.

OptionOutputs Log Levels

no logging options

LIFECYCLE and higher

-q or --quiet

QUIET and higher

-w or --warn

WARN and higher

-i or --info

INFO and higher

-d or --debug

DEBUG and higher (that is, all log messages)


Note: reference official docs