• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

sherter/google-java-format-gradle-plugin

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

sherter/google-java-format-gradle-plugin

开源软件地址(OpenSource Url):

https://github.com/sherter/google-java-format-gradle-plugin

开源编程语言(OpenSource Language):

Groovy 74.6%

开源软件介绍(OpenSource Introduction):

google-java-format-gradle-plugin

A Gradle plugin that utilizes google-java-format to format the Java source files in your Gradle project.

Build Status

Quick Start

  • Apply the plugin in your build script (follow these instructions for Gradle versions below 2.1)

    plugins {
      id 'com.github.sherter.google-java-format' version '0.9'
    }
  • Make sure you have defined a repository that contains version 1.8 of google-java-format

    repositories {
      mavenCentral()
    }
  • Execute the task googleJavaFormat to format all *.java files in the project

    $ ./gradlew goJF
  • Execute the task verifyGoogleJavaFormat to verify that all *.java files are formatted properly

    $ ./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 0.9 this value defaults to 1.8. On every new release the default value will be updated to the latest version of google-java-format.

    googleJavaFormat {
      toolVersion = '1.1-SNAPSHOT'
    }
  • Choose betweeen 'GOOGLE' (default) and 'AOSP' style by setting the style option:

    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 SourceTask to set these inputs. Initially, a 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 Ant-style exclude patterns). The chapter about Working With Files in the Gradle user guide might be worth reading.

    googleJavaFormat {
      source = sourceSets*.allJava
      source 'src/special_dir'
      include '**/*.java'
      exclude '**/*Template.java'
      exclude 'src/test/template_*'
    }
  • All tasks are of type 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 VerificationTask.

    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.

  • An additional include filter can be applied on the command line at execution time by setting the <taskName>.include system property. All input files that remain after applying the filters in build.gradle also have to match at least one of the patterns in the comma separated list in order to be eventually processed by the task. Note that this only allows you to further reduce the number of processed files. You can not use this to add another include method call to a task. (See contrib/pre-commit for a useful application of this feature).

    $ ./gradlew verGJF -DverifyGoogleJavaFormat.include="*Foo.java,bar/Baz.java"

Snapshots

On every push to the master branch Travis runs the tests and, if all tests pass, publishes the built artifact to Sonatype’s snapshots repository. Use the following build script snippet for the current snapshot version:

buildscript {
  repositories {
    maven {
      url 'https://oss.sonatype.org/content/repositories/snapshots/'
    }
  }
  dependencies {
    classpath 'com.github.sherter.googlejavaformatgradleplugin:google-java-format-gradle-plugin:0.9-SNAPSHOT'
  }
}

apply plugin: 'com.github.sherter.google-java-format'



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap