Skip to content

stefan-jaeger/gradle-cruft-plugin

Repository files navigation

Gradle Plugin for Cruft

This Plugin integrated basic Cruft tasks as part of your build. This Plugin does not install python pip itself. A valid setup is mandatory for this Plugin to work.

See how to install cruft.

The only intention of this Plugin is to simplify the usage of cruft and to integrate it into gradle builds.

Features:

  • Check if the linked Cookiecutter template has been updated
  • Show the diff between the project and the current cruft template.
  • Link an existing project to a Cookiecutter template
  • Update the project to the latest version of the linked Cookiecutter template

NOTE: This plugin is based on use-python plugin. Have a look at its documentation for custom python configurations.

Documentation

  • Gradle Tasks cruft
    • checkCruft
    • diffCruft
    • linkCruft
    • updateCruft

Setup

buildscript {
    repositories {
      maven {
        url "https://plugins.gradle.org/m2/"
      }
    }
    dependencies {
        classpath 'de.0x3.cruft:1.2.0'
    }
}
apply plugin: 'de.0x3.cruft'

OR

pluginManagement {
  repositories {
    gradlePluginPortal()
  }
}
plugins {
  id 'de.0x3.cruft' version '1.2.0'
}

Compatibility

Java

This plugin was compiled for java 11 and should be compatible with java 17+. additionally all requirements of cruft apply to this Plugin as well.

Gradle

Gradle Version
7.x 1.0.0
7.x 1.1.0
7.x 1.1.1
7.x 1.2.0

Python & Pip

Make sure python and pip are installed:

python --version  
pip --version

Configuration

cruft {
    projectDir = '.'    // Path to the project directory
    checkout = '123asd' // The git reference to check against. Supports branches, tags and commit hashes.
    strict = true
    // If enabled, ensures that the project is updated to be the same as the checked out cookiecutter template
    check {
        projectDir = '.'    // Overwrite global configuration
        checkout = '123asd' // Overwrite global configuration
        strict = true   // Overwrite global configuration
    }
    diff { // diffCruft task configuration
        projectDir = '.'    // Overwrite global configuration
        checkout = '123asd' // Overwrite global configuration
        exitCode = false    // Overwrite global configuration
    }
    link { // linkCruft task configuration
        projectDir = '.'    // Overwrite global configuration
        checkout = '123asd' // Overwrite global configuration
        configFile = 'config.json'  // Path to the Cookiecutter user config file
        defaultConfig = false   // Do not load a config file. Use the defaults instead
        extraContext = '{}' // A JSON string describing any extra context to pass to cookiecutter.
        template = 'ssh://gitrepo/template.git' //
        directory = 'cookiecutter'  // Directory within repo that holds cookiecutter.json file for advanced repositories
        // with multi templates in it
    }
    update { // update task configuration
        projectDir = '.'    // Overwrite global configuration
        checkout = '123asd' // Overwrite global configuration
        refreshPrivateVariables = false // Refresh cookiecutter private variables for the latest template version
        skipUpdate = false  // Skip the template updates but update the cruft state
        strict = true   // Overwrite global configuration
        allowUntrackedFiles = false // Allow the project's cruft to be updated if there are untracked files in the git
    }
}

Reference Links