<commit_before>= google-java-format-gradle-plugin
:release-version: 0.5
:default-google-java-format-version: 1.1
:snapshot-version: 0.6-SNAPSHOT


A https://github.com/gradle/gradle[Gradle] plugin that utilizes
https://github.com/google/google-java-format[google-java-format] to
format the Java source files in your Gradle project.

image:https://travis-ci.org/sherter/google-java-format-gradle-plugin.svg?branch=master["Build
Status",
link="https://travis-ci.org/sherter/google-java-format-gradle-plugin"]

== Quick Start
* Apply the plugin in your build script (follow https://plugins.gradle.org/plugin/com.github.sherter.google-java-format[these instructions]
for Gradle versions below `2.1`)
+
[source,groovy]
[subs="attributes"]
----
plugins {
  id 'com.github.sherter.google-java-format' version '{release-version}'
}
----
+

* Make sure you have defined a repository that contains version `{default-google-java-format-version}` of `google-java-format`
+
[source,groovy]
----
repositories {
  jcenter()  // or mavenCentral()
}
----

* Execute the task `googleJavaFormat` to format all `*.java` files in the project
+
[source,shell]
----
$ ./gradlew goJF
----
+
* Execute the task `verifyGoogleJavaFormat` to verify that all `*.java` files are formatted properly
+
[source,shell]
----
$ ./gradlew verGJF
----

== Extended Usage
* The plugin adds the extension `googleJavaFormat` to your project. Adjust the variable `toolVersion` to use a specific version of `google-java-format`. You can even define `SNAPSHOT` versions, but make sure that you have added a repository to the project that contains this version (e.g. `mavenLocal()`). For plugin version `{release-version}` this value defaults to `{default-google-java-format-version}`. On every new release the default value will be updated to the latest version of `google-java-format`.
+
[source,groovy]
[subs="attributes"]
----
googleJavaFormat {
  toolVersion '1.1-SNAPSHOT'
}
----

* Choose betweeen `'GOOGLE'` (default) and `'AOSP'` style by setting the style option:
+
[source,groovy]
----
googleJavaFormat {
  options style: 'AOSP'
}
----

* The predefined tasks `googleJavaFormat` and `verifyGoogleJavaFormat` by default process all `*.java` files found in the project or any subproject (except for files in a `buildDir`). They are of type `https://docs.gradle.org/2.0/javadoc/org/gradle/api/tasks/SourceTask.html[SourceTask]` and can be configured accordingly. For example, if you want to exclude specific files from a predefined task you can use https://docs.gradle.org/2.0/javadoc/org/gradle/api/tasks/util/PatternFilterable.html[Ant-style exclude patterns].
+
[source,groovy]
[subs="attributes"]
----
tasks.googleJavaFormat {
  exclude '**/*Template.java'
  exclude 'src/test/template_*'
}
----
+
You can also overwrite the default inputs and use your own rules (see `https://docs.gradle.org/current/userguide/working_with_files.html[Working With Files]`)
+
[source,groovy]
[subs="attributes"]
----
tasks.verifyGoogleJavaFormat {
  setSource fileTree('subprojects')
  include '**/*.java'
}
----

* Define your own format or verification tasks, if you need more than the predefined ones. The task type `VerifyGoogleJavaFormat` also implements the interface `https://docs.gradle.org/2.0/javadoc/org/gradle/api/tasks/VerificationTask.html[VerificationTask]`.
+
[source,groovy]
----
import com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormat
import com.github.sherter.googlejavaformatgradleplugin.VerifyGoogleJavaFormat

task format(type: GoogleJavaFormat) {
  source 'src/main'
  source 'src/test'
  include '**/*.java'
  exclude '**/*Template.java'
}

task verifyFormatting(type: VerifyGoogleJavaFormat) {
  source 'src/main'
  include '**/*.java'
  ignoreFailures true
}
----



== Snapshots
On every push to the master branch https://travis-ci.org/[Travis] runs
the tests and, if all tests pass, publishes the built artifact to
https://oss.sonatype.org/content/repositories/snapshots/[Sonatype's
`snapshots` repository]. Use the following build script snippet for
the current snapshot version:

[source,groovy]
[subs="attributes"]
----
buildscript {
  repositories {
    maven {
      url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
  }
  dependencies {
    classpath 'com.github.sherter.googlejavaformatgradleplugin:google-java-format-gradle-plugin:{snapshot-version}'
  }
}
<commit_msg>Document how default inputs can be configured<commit_after>= google-java-format-gradle-plugin
:release-version: 0.5
:default-google-java-format-version: 1.1
:snapshot-version: 0.6-SNAPSHOT


A https://github.com/gradle/gradle[Gradle] plugin that utilizes
https://github.com/google/google-java-format[google-java-format] to
format the Java source files in your Gradle project.

image:https://travis-ci.org/sherter/google-java-format-gradle-plugin.svg?branch=master["Build
Status",
link="https://travis-ci.org/sherter/google-java-format-gradle-plugin"]

== Quick Start
* Apply the plugin in your build script (follow https://plugins.gradle.org/plugin/com.github.sherter.google-java-format[these instructions]
for Gradle versions below `2.1`)
+
[source,groovy]
[subs="attributes"]
----
plugins {
  id 'com.github.sherter.google-java-format' version '{release-version}'
}
----
+

* Make sure you have defined a repository that contains version `{default-google-java-format-version}` of `google-java-format`
+
[source,groovy]
----
repositories {
  jcenter()  // or mavenCentral()
}
----

* Execute the task `googleJavaFormat` to format all `*.java` files in the project
+
[source,shell]
----
$ ./gradlew goJF
----
+
* Execute the task `verifyGoogleJavaFormat` to verify that all `*.java` files are formatted properly
+
[source,shell]
----
$ ./gradlew verGJF
----

== Extended Usage
* The plugin adds the extension `googleJavaFormat` to your project. Adjust the variable `toolVersion` to use a specific version of `google-java-format`. You can even define `SNAPSHOT` versions, but make sure that you have added a repository to the project that contains this version (e.g. `mavenLocal()`). For plugin version `{release-version}` this value defaults to `{default-google-java-format-version}`. On every new release the default value will be updated to the latest version of `google-java-format`.
+
[source,groovy]
[subs="attributes"]
----
googleJavaFormat {
  toolVersion '1.1-SNAPSHOT'
}
----

* Choose betweeen `'GOOGLE'` (default) and `'AOSP'` style by setting the style option:
+
[source,groovy]
----
googleJavaFormat {
  options style: 'AOSP'
}
----

* The extension object allows you to configure the default inputs for all tasks related to this plugin. It provides the same methods as a `https://docs.gradle.org/2.0/javadoc/org/gradle/api/tasks/SourceTask.html[SourceTask]` to set these inputs. Initially, a `https://docs.gradle.org/current/javadoc/org/gradle/api/file/FileTree.html[FileTree]` that contains all `*.java` files in the project directory (and recursivly all subdirectories, excluding files in a (sub)project's `buildDir`) is added with one `source` method call. However, this initial value for the default inputs can be overwritten (using `setSource`), extended (using additional `source` calls) and/or further filtered (using `include` and/or `exclude` patterns, see https://docs.gradle.org/2.0/javadoc/org/gradle/api/tasks/util/PatternFilterable.html[Ant-style exclude patterns]). The chapter about `https://docs.gradle.org/current/userguide/working_with_files.html[Working With Files]` in the Gradle user guide might be worth reading.
+
[source,groovy]
[subs="attributes"]
----
googleJavaFormat {
  setSource sourceSets*.java
  source 'src/special_dir'
  include '**/*.java'
  exclude '**/*Template.java'
  exclude 'src/test/template_*'
}
----

* All tasks are of type `https://docs.gradle.org/2.0/javadoc/org/gradle/api/tasks/SourceTask.html[SourceTask]` and can be configured accordingly. In addition to the default tasks `googleJavaFormat` and `verifyGoogleJavaFormat` you can define custom tasks if you like. The task type `VerifyGoogleJavaFormat` also implements the interface `https://docs.gradle.org/2.0/javadoc/org/gradle/api/tasks/VerificationTask.html[VerificationTask]`.
+
[source,groovy]
----
import com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormat
import com.github.sherter.googlejavaformatgradleplugin.VerifyGoogleJavaFormat

task format(type: GoogleJavaFormat) {
  source 'src/main'
  source 'src/test'
  include '**/*.java'
  exclude '**/*Template.java'
}

task verifyFormatting(type: VerifyGoogleJavaFormat) {
  source 'src/main'
  include '**/*.java'
  ignoreFailures true
}
----
If you set sources in a task (by calling `setSource` and/or `source`), the default inputs from the extension object are *not* added to the final set of sources to process. However, if you don't modify the sources in the task and only add `include` and/or `exclude` patterns, the default inputs are first added and then further filtered according the the patterns.


== Snapshots
On every push to the master branch https://travis-ci.org/[Travis] runs
the tests and, if all tests pass, publishes the built artifact to
https://oss.sonatype.org/content/repositories/snapshots/[Sonatype's
`snapshots` repository]. Use the following build script snippet for
the current snapshot version:

[source,groovy]
[subs="attributes"]
----
buildscript {
  repositories {
    maven {
      url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
  }
  dependencies {
    classpath 'com.github.sherter.googlejavaformatgradleplugin:google-java-format-gradle-plugin:{snapshot-version}'
  }
}

{'fraction_non_alphanumeric': 0.1302582257392753, 'fraction_numerical': 0.003540191586838817, 'mean_word_length': 4.53921568627451, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 26, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1485070', 'n_tokens_mistral': 3015, 'n_tokens_neox': 2910, 'n_words': 856}