1. Introduction

Gradle plugin for generating .gitignore files using gitignore.io.

1.1. Features

  • Templates supplied by gitignore.io, so they are always up-to-date.

  • Automatic generation of the gitignore file based on the following project facets:

    • Programming Languages

    • Development Environment

    • Operating System

  • Generation of the gitignore file is completely configurable.

  • Support for pulling gitignore templates from locations other than gitignore.io.

For detailed information on getting started with this plugin and how to configure specific tasks, please refer to the documentation below.

2. Getting Started

The plugin can be applied with the plugin DSL or the buildscript syntax.

2.1. Plugin DSL

Groovy
plugins {
    id "com.github.gregwhitaker.gitignore" version "2.2.0"
}

2.2. Buildscript Syntax

Groovy
buildscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "gradle.plugin.com.github.gregwhitaker:gradle-gitignore-plugin:2.2.0"
    }
}

apply plugin: "com.github.gregwhitaker.gitignore"

No other configuration is necessary at this point. The plugin will auto-detect the appropriate gitignore facets and automatically generate a .gitgnore file.

If you wish to override any of the configuration options, you can through the gitignore extension detailed below.

3. Tasks

The plugin applies default tasks, which can be executed from the Gradle command line:

Task Name Type Usage Description

createGitIgnore

Default

./gradlew createGitIgnore

Creates a .gitignore file for the project.

deleteGitIgnore

Default

./gradlew deleteGitIgnore

Deletes the .gitignore file for the project.

listGitIgnoreFacets

Default

./gradlew listGitIgnoreFacets

Lists all of the supported project facets.

printGitIgnore

Default

./gradlew printGitIgnore

Prints the .gitignore file for the project.

4. Create GitIgnore

There are a number of options for creating .gitignore files with this plugin.

4.1. Simple Configuration

When using the plugin with simple configuration there is no need for a configuration block. Simply apply the plugin, as detailed above, and a .gitignore file will be automatically generated.

4.2. Advanced Configuration

The plugin uses "facets" to describe what rules to add to the .gitignore file. These facets correspond to the technology selections on the gitignore.io website.

When using advanced configuration the plugin will continue to automatically discover project facets, but you are also able to add your own facets to the generation process by using the facets configuration parameter.

Groovy
gitignore {
    facets = [
            'linux',
            'eclipse'
    ]
}

4.3. Manual Configuration

Automatic discovery of project facets can be disabled allowing you to configure all facets that will be used for generation of the .gitignore file by calling the noAutoDetect() configuration method.

Groovy
gitignore {
    noAutoDetect()
    facets = [
            'java',
            'idea',
            'gradle'
    ]
}

4.4. External Configuration

In the event that you do not want to use gitignore.io to generate the .gitignore file you can insert any hosted document using the url configuration parameter.

Groovy
gitignore {
    url = 'https://raw.githubusercontent.com/gregwhitaker/gradle-gitignore-plugin/master/src/templates/template-gitignore?token=AFw8vOxtg_dhIKrIKO1-aKjhpcvuxB6Kks5YhFcIwA%3D%3D'
}

5. Delete GitIgnore

Deletes the existing .gitignore file if it exists.

5.1. Example

Bash
./gradlew deleteGitIgnore

6. List GitIgnore Facets

Lists all of the supported project facets that can be used to create the .gitignore file.

6.1. Example

Bash
./gradlew listGitIgnoreFacets

Prints the current .gitignore file to the terminal.

7.1. Example

Bash
./gradlew printGitIgnore