Giter VIP home page Giter VIP logo

gradle-format-plugin's Introduction

Not (actively) maintained anymore, you might want to check out the Spotless Gradle plugin

Gradle Format plugin

The Gradle Format plugin enables you to format your Java sources. It operates in place and can be used for instance before pushing changes to enforce a coding style. The formatting can be customized using a properties or XML file with the keys defined in DefaultCodeFormatterConstants from Eclipse. See src/test/resources/ for examples. Eventually you should be able to export Eclipse settings to this file.

The plugin also enables you to sort imports.

Usage

To use the Format plugin, include in your build script:

apply plugin: 'com.github.youribonnaffe.gradle.format'

Note that the Java plugin will be applied too.

To run it:

gradle format

The plugin JAR needs to be accessible in the classpath of your build script. It is directly available on Gradle plugins. Alternatively, you can download it from GitHub and deploy it to your local repository. The following code snippet shows an example on how to get it and use it:

plugins {
  id "com.github.youribonnaffe.gradle.format" version "1.5"
}

Tasks

The Format plugin defines the following tasks:

  • format: Format Java source code

Properties

The Format task defines the following properties:

  • configurationFile: The formatter configuration (File)
  • importsOrder: The import orders (List of strings)
  • importsOrderConfigurationFile: The import orders (a file using Eclipse format)
  • files: The files to format (FileCollection), defaults are Java sources from main and test SourceSets

Example

format {
    configurationFile = file('myformatsettings.properties')
    importsOrder = ["java", "javax", "org", "\\#com.something.StaticImport"]
    files = sourceSets.main.java
}

Acknowledgements

Using Hibernate Tools JavaFormatter

Import ordering from EclipseCodeFormatter

Readme format from https://github.com/bmuschko/gradle-gae-plugin

gradle-format-plugin's People

Contributors

youribonnaffe avatar obecker avatar

Watchers

James Cloos avatar dev.with avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.