google-java-format-gradle-plugin | Gradle plugin that utilizes google | Plugin library
kandi X-RAY | google-java-format-gradle-plugin Summary
kandi X-RAY | google-java-format-gradle-plugin Summary
A Gradle plugin that utilizes google-java-format to format the Java source files in your Gradle project.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of google-java-format-gradle-plugin
google-java-format-gradle-plugin Key Features
google-java-format-gradle-plugin Examples and Code Snippets
Community Discussions
Trending Discussions on google-java-format-gradle-plugin
QUESTION
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
:
ANSWER
Answered 2020-Nov-02 at 20:48A 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:
QUESTION
We wired https://github.com/sherter/google-java-format-gradle-plugin into our project per the readme.
We also wired in a pre-commit hook to run the plugin before committing, which ensures that all of the code in a changelist is formatted before pushing it, which avoids errors in Jenkins when we run the verGJF
task.
But we have to keep remembering to run goJF
locally before running ./gradlew build
, or the build fails with formatting errors.
We worked around this by adding the https://plugins.jetbrains.com/plugin/8527-google-java-format and https://plugins.jetbrains.com/plugin/7642-save-actions plugins for IntelliJ, enabling the google-java-format plugin, and configuring the save-actions plugin to format on save.
But that's a lot of extra configuration a developer has to remember to go through, plus it means they can't format code the way they want while working on it, and only have it be reformatted at the point of build or commit.
We'd prefer an all-Gradle solution, so that the goJF
task is run before the build
task (and before the verGJF
task, which is already bound to the build
task by the google-java-format Gradle plugin).
We couldn't figure out how to do that. Does someone else know?
...ANSWER
Answered 2020-Apr-05 at 05:30It sounds like you want to essentially always ensure that the code is properly formatted before the verifyGoogleJavaFormat
task is run (and could complain). In that case, I’d simply make the googleJavaFormat
task a dependency of the verifyGoogleJavaFormat
task. In your build.gradle
file, after you have applied the google-java-format plugin, simply add the following:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install google-java-format-gradle-plugin
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 { jcenter() // or 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
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:.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page