kandi background
Explore Kits

google-java-format | Reformats Java source code to comply with Google Java Style. | Build Tool library

 by   google Java Version: v1.15.0 License: Apache-2.0

 by   google Java Version: v1.15.0 License: Apache-2.0

Download this library from

kandi X-RAY | google-java-format Summary

google-java-format is a Java library typically used in Utilities, Build Tool, Spring Boot, Gradle, Maven applications. google-java-format has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. However google-java-format has 7 bugs. You can download it from GitHub.
google-java-format is a program that reformats Java source code to comply with Google Java Style.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • google-java-format has a highly active ecosystem.
  • It has 4425 star(s) with 759 fork(s). There are 141 watchers for this library.
  • There were 1 major release(s) in the last 6 months.
  • There are 77 open issues and 316 have been closed. On average issues are closed in 93 days. There are 14 open pull requests and 0 closed requests.
  • It has a negative sentiment in the developer community.
  • The latest version of google-java-format is v1.15.0
google-java-format Support
Best in #Build Tool
Average in #Build Tool
google-java-format Support
Best in #Build Tool
Average in #Build Tool

quality kandi Quality

  • google-java-format has 7 bugs (0 blocker, 1 critical, 4 major, 2 minor) and 420 code smells.
google-java-format Quality
Best in #Build Tool
Average in #Build Tool
google-java-format Quality
Best in #Build Tool
Average in #Build Tool

securitySecurity

  • google-java-format has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • google-java-format code analysis shows 0 unresolved vulnerabilities.
  • There are 1 security hotspots that need review.
google-java-format Security
Best in #Build Tool
Average in #Build Tool
google-java-format Security
Best in #Build Tool
Average in #Build Tool

license License

  • google-java-format is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
google-java-format License
Best in #Build Tool
Average in #Build Tool
google-java-format License
Best in #Build Tool
Average in #Build Tool

buildReuse

  • google-java-format releases are available to install and integrate.
  • Build file is available. You can build the component from source.
  • Installation instructions are not available. Examples and code snippets are available.
  • google-java-format saves you 8341 person hours of effort in developing the same functionality from scratch.
  • It has 17132 lines of code, 1096 functions and 80 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
google-java-format Reuse
Best in #Build Tool
Average in #Build Tool
google-java-format Reuse
Best in #Build Tool
Average in #Build Tool
Top functions reviewed by kandi - BETA

kandi has reviewed google-java-format and discovered the below as its top functions. This is intended to give you an instant insight into google-java-format implemented functionality, and help decide if they suit your requirements.

  • Visit a method node .
  • Builds the output of this doc .
  • Convert this range set to a regular expression for re - formatting .
  • Consumes a token .
  • Renders tokens .
  • Setup UI .
  • Format the files .
  • Builds tokens after a given list of tokens .
  • Writes a token .
  • scan imports .

google-java-format Key Features

Reformats Java source code to comply with Google Java Style.

from the command-line

copy iconCopydownload iconDownload
java -jar /path/to/google-java-format-${GJF_VERSION?}-all-deps.jar <options> [files...]

as a library

copy iconCopydownload iconDownload
<dependency>
  <groupId>com.google.googlejavaformat</groupId>
  <artifactId>google-java-format</artifactId>
  <version>${google-java-format.version}</version>
</dependency>

Building from source

copy iconCopydownload iconDownload
mvn install

License

copy iconCopydownload iconDownload
Copyright 2015 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy of
the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.

Gradle: Call Task from Imported Plugin in My Own Tasks

copy iconCopydownload iconDownload
~> gradle gooJF
~> gradle googleJavaFormat
task SomeTaskName(type: SomeClassImplementingTheTask) {
  // some configuration of the task
}
googleJavaFormat {
  source = sourceSets*.allJava
  source 'src/special_dir'
  include '**/*.java'
  exclude '**/*Template.java'
  exclude 'src/test/template_*'
}
~> gradle googleJavaFormat
~> gradle verifyGoogleJavaFormat
-----------------------
~> gradle gooJF
~> gradle googleJavaFormat
task SomeTaskName(type: SomeClassImplementingTheTask) {
  // some configuration of the task
}
googleJavaFormat {
  source = sourceSets*.allJava
  source 'src/special_dir'
  include '**/*.java'
  exclude '**/*Template.java'
  exclude 'src/test/template_*'
}
~> gradle googleJavaFormat
~> gradle verifyGoogleJavaFormat
-----------------------
~> gradle gooJF
~> gradle googleJavaFormat
task SomeTaskName(type: SomeClassImplementingTheTask) {
  // some configuration of the task
}
googleJavaFormat {
  source = sourceSets*.allJava
  source 'src/special_dir'
  include '**/*.java'
  exclude '**/*Template.java'
  exclude 'src/test/template_*'
}
~> gradle googleJavaFormat
~> gradle verifyGoogleJavaFormat
-----------------------
~> gradle gooJF
~> gradle googleJavaFormat
task SomeTaskName(type: SomeClassImplementingTheTask) {
  // some configuration of the task
}
googleJavaFormat {
  source = sourceSets*.allJava
  source 'src/special_dir'
  include '**/*.java'
  exclude '**/*Template.java'
  exclude 'src/test/template_*'
}
~> gradle googleJavaFormat
~> gradle verifyGoogleJavaFormat
-----------------------
~> gradle gooJF
~> gradle googleJavaFormat
task SomeTaskName(type: SomeClassImplementingTheTask) {
  // some configuration of the task
}
googleJavaFormat {
  source = sourceSets*.allJava
  source 'src/special_dir'
  include '**/*.java'
  exclude '**/*Template.java'
  exclude 'src/test/template_*'
}
~> gradle googleJavaFormat
~> gradle verifyGoogleJavaFormat
-----------------------
~> gradle gooJF
~> gradle googleJavaFormat
task SomeTaskName(type: SomeClassImplementingTheTask) {
  // some configuration of the task
}
googleJavaFormat {
  source = sourceSets*.allJava
  source 'src/special_dir'
  include '**/*.java'
  exclude '**/*Template.java'
  exclude 'src/test/template_*'
}
~> gradle googleJavaFormat
~> gradle verifyGoogleJavaFormat
-----------------------
plugins {
    id 'java'
    // https://github.com/sherter/google-java-format-gradle-plugin
    id 'com.github.sherter.google-java-format' version '0.9'
}

import com.github.sherter.googlejavaformatgradleplugin.GoogleJavaFormat
import com.github.sherter.googlejavaformatgradleplugin.VerifyGoogleJavaFormat

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.google.guava:guava:30.0-jre")
    testImplementation(platform('org.junit:junit-bom:5.7.0'))
    testImplementation('org.junit.jupiter:junit-jupiter:5.7.0')
}

task fmt(type: GoogleJavaFormat) {
}

task vfmt(type: VerifyGoogleJavaFormat) {
}

test {
    useJUnitPlatform()
}

Gradle monobuild and map of jar files for all gradle composite builds

copy iconCopydownload iconDownload
./gradlew :server1:build

Apache Camel Timer Nullpointer exception at Fat Jar

copy iconCopydownload iconDownload
plugins {
    id 'java'
    id 'application'
    id 'com.github.sherter.google-java-format' version '0.8'
    id "com.github.johnrengelman.shadow" version "6.0.0" // Added plugin
}
repositories {
    jcenter()
}
dependencies {
    // ...
}
application {
    mainClassName = 'com.eip.App'
}
// Removed jar step
test {
    useJUnitPlatform()
}
googleJavaFormat {
    exclude '**/App.java'
}
// Added shadow plugin configuration
shadowJar {
    mergeServiceFiles() // Tell plugin to merge duplicate service files
    manifest {
        attributes 'Main-Class': 'com.eip.App'
    }
}
apply plugin: 'com.github.johnrengelman.shadow'
java -jar build/libs/app-all.jar
-----------------------
plugins {
    id 'java'
    id 'application'
    id 'com.github.sherter.google-java-format' version '0.8'
    id "com.github.johnrengelman.shadow" version "6.0.0" // Added plugin
}
repositories {
    jcenter()
}
dependencies {
    // ...
}
application {
    mainClassName = 'com.eip.App'
}
// Removed jar step
test {
    useJUnitPlatform()
}
googleJavaFormat {
    exclude '**/App.java'
}
// Added shadow plugin configuration
shadowJar {
    mergeServiceFiles() // Tell plugin to merge duplicate service files
    manifest {
        attributes 'Main-Class': 'com.eip.App'
    }
}
apply plugin: 'com.github.johnrengelman.shadow'
java -jar build/libs/app-all.jar

Failed to create Blob container in Microsoft Azure

copy iconCopydownload iconDownload
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-storage-blob</artifactId>
    <version>12.0.0</version>
</dependency>
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString("DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net").buildClient();

//Create a unique name for the container
String containerName = "quickstartblobs";

// Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);
-----------------------
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-storage-blob</artifactId>
    <version>12.0.0</version>
</dependency>
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString("DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net").buildClient();

//Create a unique name for the container
String containerName = "quickstartblobs";

// Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);
-----------------------
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-storage-blob</artifactId>
    <version>12.0.0</version>
</dependency>
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString("DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx;EndpointSuffix=core.windows.net").buildClient();

//Create a unique name for the container
String containerName = "quickstartblobs";

// Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);

How can I configure Gradle google-java-format plugin to run goJF in the build step?

copy iconCopydownload iconDownload
verifyGoogleJavaFormat.dependsOn(tasks.googleJavaFormat)
build.dependsOn(tasks.googleJavaFormat)
verifyGoogleJavaFormat.mustRunAfter(tasks.googleJavaFormat)
-----------------------
verifyGoogleJavaFormat.dependsOn(tasks.googleJavaFormat)
build.dependsOn(tasks.googleJavaFormat)
verifyGoogleJavaFormat.mustRunAfter(tasks.googleJavaFormat)

How to format code according to google java format

copy iconCopydownload iconDownload
mvn fmt:check
-----------------------
<build>
  <plugins>
    <plugin>
      <groupId>com.cosium.code</groupId>
      <artifactId>maven-git-code-format</artifactId>
      <version>VERSION</version>
      <executions>
        <execution>
          <goals>
            <goal>install-hooks</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
    <plugin>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>VERSION</version>
      <executions>
        <execution>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <requireMavenVersion>
                <version>[3.5.4,)</version>
              </requireMavenVersion>
            </rules>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

Google Styleguide Java Format for VSCode

copy iconCopydownload iconDownload
"java.configuration.updateBuildConfiguration": "automatic",
"checkstyle.enable": true,
"checkstyle.configurationPath": "config/checkstyle/checkstyle.xml",
"checkstyle.checkstylePath": "C:/dev/tools/checkstyle-8.8-all.jar"
-----------------------
$ code --install-extension emeraldwalk.RunOnSave
# Example using Homebrew on OS X
$ brew install google-java-format
{
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.java$",
        "cmd": "google-java-format --replace ${file}"
      },
    ],
  },
}
-----------------------
$ code --install-extension emeraldwalk.RunOnSave
# Example using Homebrew on OS X
$ brew install google-java-format
{
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.java$",
        "cmd": "google-java-format --replace ${file}"
      },
    ],
  },
}
-----------------------
$ code --install-extension emeraldwalk.RunOnSave
# Example using Homebrew on OS X
$ brew install google-java-format
{
  "emeraldwalk.runonsave": {
    "commands": [
      {
        "match": "\\.java$",
        "cmd": "google-java-format --replace ${file}"
      },
    ],
  },
}

Sherter Gradle plugin for pre-commit

copy iconCopydownload iconDownload
gradlew
/scripts
   pre-commit-script
/src

How to exclude an annotation processor dependency from ProGuard

copy iconCopydownload iconDownload
// Auto factory for Assisted Injection
annotationProcessor "com.google.auto.factory:auto-factory:${libs.autoFactoryVersion}"
provided "com.google.auto.factory:auto-factory:${libs.autoFactoryVersion}"
-----------------------
-dontwarn com.google.googlejavaformat.**
-dontwarn com.google.common.**

Community Discussions

Trending Discussions on google-java-format
  • Gradle: Call Task from Imported Plugin in My Own Tasks
  • Gradle monobuild and map of jar files for all gradle composite builds
  • Apache Camel Timer Nullpointer exception at Fat Jar
  • Failed to create Blob container in Microsoft Azure
  • How can I configure Gradle google-java-format plugin to run goJF in the build step?
  • How to format code according to google java format
  • Google Styleguide Java Format for VSCode
  • Google code style formats maven pom strange in Intellij
  • Git checking out a specific file only with LF line endings on Windows despite core.autocrlf=true
  • Sherter Gradle plugin for pre-commit
Trending Discussions on google-java-format

QUESTION

Gradle: Call Task from Imported Plugin in My Own Tasks

Asked 2020-Nov-02 at 22:34

I'm used to Maven but currently I'm using Gradle and I'm not really sure how to call tasks defined by other plugins. (Edit: I'm able to call these tasks in the CLI, but I'd like to also invoke them in my own, custom-defined tasks.)

But I'm importing this plugin to format (and enforce format) of my Java project; the tasks I'm most interested in calling are goJF and verGJF.

I've tried a few ways to either call included tasks and I've done even more Googling. I can share some of the (probably embarrassing) ways I've tried to call other tasks if it's helpful, but figured that might be unnecessary information at this point.

Here is my build.gradle:

plugins {
    id 'java'
    // https://github.com/sherter/google-java-format-gradle-plugin
    id 'com.github.sherter.google-java-format' version '0.9'
}

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

repositories {
    mavenCentral()
}

dependencies {
    implementation("com.google.guava:guava:30.0-jre")
    testImplementation(platform('org.junit:junit-bom:5.7.0'))
    testImplementation('org.junit.jupiter:junit-jupiter:5.7.0')
}

// Alias for goJF:
task fmt  {
    goJF
}

// Alias for verGJF:
task vfmt {
    verGJF
}

test {
    useJUnitPlatform()
}

ANSWER

Answered 2020-Nov-02 at 20:48

A few distinctions to begin with. The built in tasks defined by the plugin are called googleJavaFormat and verifyGoogleJavaFormat.

These tasks are immediately available to you once you have included the plugin which it seems you have done correctly from what I can see.

On the gradle command line, gradle implements a abbreviation functionality where you can call things with shorthand like:

~> gradle gooJF

which is shorthand for:

~> gradle googleJavaFormat

but this only works on the command line and only as long as your shorthand uniquely identifies a task name.

So when you work with tasks in the build.gradle file you will need to use the full name.

In gradle you create a new task via:

task SomeTaskName(type: SomeClassImplementingTheTask) {
  // some configuration of the task
}

In your case you would want to do one of two things:

  1. configure the two existing tasks added by the plugin so that they do what you want or if the tasks already do what they should, you might not need to configure them and can just run them as is.
  2. create your own tasks with your own names but using the implementing classes (i.e. replacing SomeClassNameImplementingTheTask above with GoogleJavaFormat or VerifyGoogleJavaFormat) defined by the plugin.

The simplest of the two is to configure the already existing tasks. This can be done as follows:

googleJavaFormat {
  source = sourceSets*.allJava
  source 'src/special_dir'
  include '**/*.java'
  exclude '**/*Template.java'
  exclude 'src/test/template_*'
}

The googleJavaFormat used here is actually a "plugin extension" which is exposed by the plugin. Plugin extensions are explicitly there for you to be able to alter the behavior of the plugin through configuration.

Note that the configurations options I defined are just examples, there are probably more things you can set here. The above would modify the two existing tasks with your custom settings and you could then call them from the command line using:

~> gradle googleJavaFormat

and

~> gradle verifyGoogleJavaFormat

Again, perhaps you don't even need to configure things and in that case you should just be able to call the tasks as in the above example.

Source https://stackoverflow.com/questions/64652901

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install google-java-format

You can download it from GitHub.
You can use google-java-format like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the google-java-format component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .

Support

Please see the contributors guide for details.

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Compare Build Tool Libraries with Highest Support
Compare Build Tool Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.