E-Book, Englisch, 368 Seiten
Klein Ikkink Gradle Effective Implementations Guide
2. Auflage 2025
ISBN: 978-1-78439-611-4
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)
This comprehensive guide will get you up and running with build automation using Gradle.
E-Book, Englisch, 368 Seiten
ISBN: 978-1-78439-611-4
Verlag: De Gruyter
Format: PDF
Kopierschutz: Adobe DRM (»Systemvoraussetzungen)
Gradle is a project automation tool that has a wide range of applications. The basic aim of Gradle is to automate a wide variety of tasks performed by software developers, including compiling computer source code to binary code, packaging binary codes, running tests, deploying applications to production systems, and creating documentation.
The book will start with the fundamentals of Gradle and introduce you to the tools that will be used in further chapters. You will learn to create and work with Gradle scripts and then see how to use Gradle to build your Java Projects. While building Java application, you will find out about other important topics such as dependency management, publishing artifacts, and integrating the application with other JVM languages such as Scala and Groovy.
By the end of this book, you will be able to use Gradle in your daily development. Writing tasks, applying plugins, and creating build logic will be your second nature.
Autoren/Hrsg.
Weitere Infos & Material
Command-line options
The command is used to execute a build. This command accepts several command-line options. We know the (or ) option to reduce the output of a build. If we use the (or or ) option, we see the complete list of options, as follows:
$ gradle --help USAGE: gradle [option...] [task...] -?, -h, --help Shows this help message. -a, --no-rebuild Do not rebuild project dependencies. -b, --build-file Specifies the build file. -c, --settings-file Specifies the settings file. --configure-on-demand Only relevant projects are configured in this build run. This means faster build for large multi-project builds. [incubating] --console Specifies which type of console output to generate. Values are 'plain', 'auto' (default) or 'rich'. --continue Continues task execution after a task failure. -D, --system-prop Set system property of the JVM (e.g. -Dmyprop=myvalue). -d, --debug Log in debug mode (includes normal stacktrace). --daemon Uses the Gradle daemon to run the build. Starts the daemon if not running. --foreground Starts the Gradle daemon in the foreground. [incubating] -g, --gradle-user-home Specifies the gradle user home directory. --gui Launches the Gradle GUI. -I, --init-script Specifies an initialization script. -i, --info Set log level to info. -m, --dry-run Runs the builds with all task actions disabled. --max-workers Configure the number of concurrent workers Gradle is allowed to use. [incubating] --no-color Do not use color in the console output. [deprecated - use --console=plain instead] --no-daemon Do not use the Gradle daemon to run the build. --offline The build should operate without accessing network resources. -P, --project-prop Set project property for the build script (e.g. -Pmyprop=myvalue). -p, --project-dir Specifies the start directory for Gradle. Defaults to current directory. --parallel Build projects in parallel. Gradle will attempt to determine the optimal number of executor threads to use. [incubating] --parallel-threads Build projects in parallel, using the specified number of executor threads. [deprecated - Please use --parallel, optionally in conjunction with --max-workers.] [incubating] --profile Profiles build execution time and generates a report in the --project-cache-dir Specifies the project-specific cache directory. Defaults to .gradle in the root project directory. -q, --quiet Log errors only. --recompile-scripts Force build script recompiling. --refresh-dependencies Refresh the state of dependencies. --rerun-tasks Ignore previously cached task results. -S, --full-stacktrace Print out the full (very verbose) stacktrace for all exceptions. -s, --stacktrace Print out the stacktrace for all exceptions. --stop Stops the Gradle daemon if it is running. -t, --continuous Enables continuous build. Gradle does not exit and will re-execute tasks when task file inputs change. [incubating] -u, --no-search-upward Don't search in parent folders for a settings.gradle file. -v, --version Print version info. -x, --exclude-task Specify a task to be excluded from execution.Logging options
Let's look at some of the options in more detail. The (or ), (or ), (or ), (or), and (or) options control how much output we see when we execute tasks. To get the most detailed output, we use the (or ) option. This option provides a lot of output with information about the steps and classes used to run the build. The output is very verbose, therefore, we will not use it much.
To get a better insight on the steps that are executed for our task, we can use the (or ) option. The output is not as verbose as with , but it can provide a better understanding of the build steps:
$ gradle --info helloworld Starting Build Settings evaluated using settings file '/master/settings.gradle'. Projects loaded. Root project using build file '/Users/mrhaki/Projects/gradle-effective-implementation-guide-2/gradle-impl-guide-2/src/docs/asciidoc/Chapter1/Code_Files/hello-world/build.gradle'. Included projects: [root project 'hello-world'] Evaluating root project 'hello-world' using build file '/Users/mrhaki/Projects/gradle-effective-implementation-guide-2/gradle-impl-guide-2/src/docs/asciidoc/Chapter1/Code_Files/hello-world/build.gradle'. All projects evaluated. Selected primary task 'helloWorld' from project : Tasks to be executed: [task ':helloWorld'] :helloWorld (Thread[main,5,main]) started. :helloWorld Executing task ':helloWorld' (up-to-date check took 0.001 secs) due to: Task has not declared any outputs. Hello world. :helloWorld (Thread[main,5,main]) completed. Took 0.021 secs. BUILD SUCCESSFUL Total time: 1.325 secs This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.12/userguide/gradle_daemon.htmlIf our build throws exceptions, we can see the stack trace information with the (or ) and (or ) options. The latter option will output the most information and is the most verbose. The and options can be combined with the other logging options.
Changing the build file and directory
We created our build file with the name. This is the default name for a build file. Gradle will look for a file with this name in the current directory to execute the build. However, we can change this with the (or ) and (or ) command-line options.
Let's run the command from the parent directory of our current directory:
$ cd .. $ gradle --project-dir hello-world -q helloWorld Hello world.We can also rename our to, for example, and still execute our build:
$ mv build.gradle hello.build $ gradle --build-file hello.build -q helloWorld Hello world.Running tasks without execution
With the (or ) option, we can run all tasks without really executing them. When we use the option, we can see the tasks that are executed, so we get an insight on the tasks that are involved in a certain build scenario. We don't even have to worry whether the tasks are actually executed. Gradle builds up a Directed Acyclic Graph (DAG) with all tasks before any task is executed. The DAG is build so that the tasks will be executed in order of dependencies, and a task is only executed once:
$ gradle --dry-run helloWorld :helloWorld SKIPPED BUILD SUCCESSFUL Total time: 1.307 secs This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.12/userguide/gradle_daemon.htmlGradle daemon
We already discussed that Gradle executes in a JVM, and each time...




