gradle.rst
author Oleksandr Gavenko <gavenkoa@gmail.com>
Sat, 18 Feb 2017 16:16:35 +0200
changeset 2095 b9bf144836b8
parent 2094 33c10259cb4d
child 2104 6931c02bbc0e
permissions -rw-r--r--
Creating multilevel project.


========
 Gradle
========
.. contents::
   :local:

Getting help
============
::

  $ gradle --help

Working with subprojects
========================

Getting list of subprojects::

  $ gradle projects

Running build on specific subproject::

  $ gradle :$SUB:clean
  $ gradle -p $SUB clean

If subproject lies in hierarchy::

  $ gradle :$SUB/$SUBSUB:clean
  $ gradle -p $SUB/$SUBSUB clean

Creating multilevel project::

  $ mkdir $PRJROOT
  $ cd $PRJROOT
  $ mkdir lvl1 lvl1/lvl2
  $ touch build.gradle lvl1/build.gradle lvl1/lvl2/build.gradle
  $ { echo include "'lvl1'"; echo include "'lvl1/lvl2'"; } >settings.gradle
  $ gradle projects

``settings.gradle`` can include per line or a list of subprojects::

  include 'sub1', 'sub2', 'sub2'
  include 'lvl1'
  include 'lvl1/lvl2'

https://docs.gradle.org/current/userguide/intro_multi_project_builds.html
http://stackoverflow.com/questions/16976214/gradle-build-only-one-module

Getting list of supported tasks
===============================
::

  $ gradle tasks

Getting list of supported tasks in each subproject::

  $ gradle tasks --all

Getting help on task::

  $ gradle -q help --task build

Similar but to each task::

  $ gradle model

Build sources
=============
::

  $ gradle compileJava
  $ gradle compileTestJava

Run main class
==============
::

  $ gradle run

Run tests
=========
::

  $ gradle test

To run tests with additional registered checks::

  $ gradle check

.. note::
   ``--rerun-tasks`` option *specifies that any task optimization is ignored*.
   In that way you may rerun tests even if there are no changed files::

     $ gradle test --rerun-tasks

Stopping server
===============
::

  $ gradle --stop

List project dependencies
=========================

List of project execution dependencies (it also download dependencies)::

  $ gradle dependencies
  $ gradle dependencies --configuration compile
  $ gradle dependencies -p $SUBPROJ
  $ gradle :$SUBPROJ:dependencies
  $ gradle :$SUBPROJ:dependencies --configuration testCompile

List of project plugin dependencies::

  $ gradle buildEnvironment
  $ gradle buildEnvironment -p $SUBPROJ
  $ gradle :$SUBPROJ:buildEnvironment

Paths to dependencies can be printed via task::

  task printDepPaths {
    doLast { configurations.runtime.each { println it } }
  }

All dependencies can be copied to single directory via task::

  task copyRuntimeLibs(type: Copy) {
    into "lib"
    from configurations.runtime
    // from configurations.testRuntime - configurations.runtime
  }

List project properties
=======================
::

  $ gradle properties
  $ gradle :$SUBPROJ:properties
  $ gradle properties -p $SUBPROJ

Dry tun
=======

``-m`` option allow parsing build scripts without actually executing them::

  $ gradle -m clean compile