Jens Schauder
Jens Schauder

Reputation: 81930

How to configure plugin properties in gradle

Among other stuff I have the following in my gradle build file

targetCompatibility = '1.8'

checkstyle {
    toolVersion = '6.6'
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.4'
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

In my limited understanding of gradle all 4 pieces are configurations for a plugin. Yet they look very different.

Apart from the different syntax, what is the semantic difference between the 4 variations?

And how am I supposed to understand from the documentation which style to use?

Upvotes: 2

Views: 2244

Answers (1)

Amnon Shochot
Amnon Shochot

Reputation: 9366

targetCompatibility = '1.8'

This is Java Plugin Convention Property, i.e. properties that allows you to set their values with project properties instead of only task properties. These properties are usually listed in the plugin documentation. You can read more about convention properties here.


checkstyle {
    toolVersion = '6.6'
}

The type of this task is CheckstyleExtension and you can find its available properties in the its DSL Documentation.


task wrapper(type: Wrapper) {
    gradleVersion = '2.4'
}

Here you define an instance of task of type Wrapper. As such, task wrapper has the same properties as the Wrapper task type which its DSL is defined here.


tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

This syntax is used for configuring all tasks of a specific type. In this case you're picking all tasks of type JavaCompile and configure their options.encoding property.

Upvotes: 3

Related Questions