Build

Build lifecycle

There are more events to listen in BuildListener.

gradle.buildFinished {
    println "Build finished"
}

We can access build settings in the build file.

gradle.settingsEvaluated { Settings settings ->
    logger.info "settingsEvaluated"
    logger.info settings
}

Keep in mind that there are 3 phases during build:

  1. Initialization

  2. Configuration

  3. Execution

settingsEvaluated is called during Initialization phase.

Deamon mode

Deamon mode is started by default. We can disable it for task execution. Also, we can stop the deamon if needed.

Partial build

We can tell Gradle to not to rebuild project in order to speed up the build time. That might be valid for project with a lot of modules.

Also, we can only build the dependents.

Upgrading Gradle

When upgrading Gradle version, it is probably wise to try out the new version first (something like dry run to verify build outputs). There is a plugin compare-gradle-builds that compares outputs from Gradle project build. That way we can check what the new version of Gradle is doing to our project.

Embedded web container

If we would like to provide embedded web container using Gradle, we can use gretty plugin.

Ant integration

We can include Ant build file into Gradle file. If there are no conflicts in task names, the Ant tasks are available via Gradle.

Lets assume we have this Ant file: ant/build.xml.

Then we can include this build.xml file in Gradle.

Then we can check what tasks were added into Gradle build.

Maven

We can migrate Maven project to Gradle. Go into Maven project folder and run gradle init. Gradle will try to migrate Maven project to Gradle. Gradle will migrate the basic stuff like dependencies. Maven plugins wont be migrated, this needs to be don manually.

Last updated

Was this helpful?