<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ankit Yadav</title>
    <description>The latest articles on DEV Community by Ankit Yadav (@ankityadav33).</description>
    <link>https://dev.to/ankityadav33</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F72720%2F467f5609-ef7b-4363-9c48-5e76d3f5f44d.jpg</url>
      <title>DEV Community: Ankit Yadav</title>
      <link>https://dev.to/ankityadav33</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ankityadav33"/>
    <language>en</language>
    <item>
      <title>Using maven build profiles to generate different artifacts</title>
      <dc:creator>Ankit Yadav</dc:creator>
      <pubDate>Wed, 20 Dec 2023 05:30:22 +0000</pubDate>
      <link>https://dev.to/ankityadav33/using-maven-build-profiles-to-generate-different-artifacts-272</link>
      <guid>https://dev.to/ankityadav33/using-maven-build-profiles-to-generate-different-artifacts-272</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Want to use the same maven Pom file to create two or more different types of artifacts (jar/war etc.) based on some condition?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can do it by Modifying pom files manually based on your requirement every time you build but this becomes tedious if you have to do it continuously. &lt;br&gt;
Also, it will be a puzzle for developers who start working on the project when you are no longer there to guide.&lt;/p&gt;

&lt;p&gt;We could use maven build profiles instead.&lt;/p&gt;

&lt;p&gt;A Build profile is a set of configuration values, which can be used to set or override default values of Maven build. Using a build profile, you can customize build for different environments such as Production v/s Development environments.&lt;/p&gt;

&lt;p&gt;Among other uses of build profiles, you can use this approach to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create builds using different parameters values&lt;/li&gt;
&lt;li&gt;Create builds with different artifact types&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Below I am going to show you a way with which you can use the maven profiles for the purpose of creating &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A Jar library file to be used as a dependency by another project.
OR&lt;/li&gt;
&lt;li&gt;A War file to be deployed to the server directly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Changes Required to the POM file for creating profiles:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;There will be some fields that will require values as parameters instead of hardcoded values:

&lt;ul&gt;
&lt;li&gt;artifactId - artifact id of the artifact created as end result&lt;/li&gt;
&lt;li&gt;packaging - to define the type of packaging like war or jar&lt;/li&gt;
&lt;li&gt;name - name of the artifact to be created&lt;/li&gt;
&lt;li&gt;description - description of the artifact&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Now these values defined as parameters above will be passed actual values based on the build profile.&lt;/li&gt;
&lt;li&gt;The first profile is for generating war package for the springboot project having id "generate-war"
We have set activateByDefault as true for this, we want the default behaviour to be creation of war file.&lt;/li&gt;
&lt;li&gt;The second is for generating library package to be used a library in other projects.&lt;/li&gt;
&lt;li&gt;You can add the dependencies based on your requirements.&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;?xml version="1.0" encoding="UTF-8"?&amp;gt;
&amp;lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"&amp;gt;
    &amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt;
    &amp;lt;parent&amp;gt;
        &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
        &amp;lt;artifactId&amp;gt;spring-boot-starter-parent&amp;lt;/artifactId&amp;gt;
        &amp;lt;version&amp;gt;2.7.16&amp;lt;/version&amp;gt;
        &amp;lt;relativePath/&amp;gt; 
    &amp;lt;/parent&amp;gt;
    &amp;lt;groupId&amp;gt;com.abc.test&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;${packaging.artifactId}&amp;lt;/artifactId&amp;gt;
    &amp;lt;version&amp;gt;0.0.1-SNAPSHOT&amp;lt;/version&amp;gt;
    &amp;lt;packaging&amp;gt;${packaging.type}&amp;lt;/packaging&amp;gt;
    &amp;lt;name&amp;gt;${packaging.name}&amp;lt;/name&amp;gt;
    &amp;lt;description&amp;gt;${packaging.description}&amp;lt;/description&amp;gt;
    &amp;lt;properties&amp;gt;
        &amp;lt;java.version&amp;gt;1.8&amp;lt;/java.version&amp;gt;
    &amp;lt;/properties&amp;gt;

    &amp;lt;dependencies&amp;gt;
        &amp;lt;dependency&amp;gt;
            &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
            &amp;lt;artifactId&amp;gt;spring-boot-starter-web&amp;lt;/artifactId&amp;gt;
        &amp;lt;/dependency&amp;gt;
        &amp;lt;!--Other dependencies--&amp;gt;
    &amp;lt;/dependencies&amp;gt;

    &amp;lt;profiles&amp;gt;
        &amp;lt;profile&amp;gt;
            &amp;lt;id&amp;gt;generate-war&amp;lt;/id&amp;gt;
            &amp;lt;properties&amp;gt;
                &amp;lt;packaging.artifactId&amp;gt;test-api&amp;lt;/packaging.artifactId&amp;gt;
                &amp;lt;packaging.type&amp;gt;war&amp;lt;/packaging.type&amp;gt;
                &amp;lt;packaging.name&amp;gt;test-api&amp;lt;/packaging.name&amp;gt;
                &amp;lt;packaging.description&amp;gt;TEST API project&amp;lt;/packaging.description&amp;gt;
            &amp;lt;/properties&amp;gt;
            &amp;lt;activation&amp;gt;
                &amp;lt;activeByDefault&amp;gt;true&amp;lt;/activeByDefault&amp;gt;
            &amp;lt;/activation&amp;gt;
            &amp;lt;build&amp;gt;
                &amp;lt;plugins&amp;gt;
                    &amp;lt;plugin&amp;gt;
                        &amp;lt;groupId&amp;gt;org.springframework.boot&amp;lt;/groupId&amp;gt;
                        &amp;lt;artifactId&amp;gt;spring-boot-maven-plugin&amp;lt;/artifactId&amp;gt;
                    &amp;lt;/plugin&amp;gt;
                    &amp;lt;!--You can any other plugins required for specific profile here--&amp;gt;
                &amp;lt;/plugins&amp;gt;
            &amp;lt;/build&amp;gt;
        &amp;lt;/profile&amp;gt;
        &amp;lt;profile&amp;gt;
            &amp;lt;id&amp;gt;generate-library&amp;lt;/id&amp;gt;
            &amp;lt;properties&amp;gt;
                &amp;lt;packaging.artifactId&amp;gt;test-api-lib&amp;lt;/packaging.artifactId&amp;gt;
                &amp;lt;packaging.type&amp;gt;jar&amp;lt;/packaging.type&amp;gt;
                &amp;lt;packaging.name&amp;gt;test-api-lib&amp;lt;/packaging.name&amp;gt;
                &amp;lt;packaging.description&amp;gt;TEST API library&amp;lt;/packaging.description&amp;gt;
            &amp;lt;/properties&amp;gt;
            &amp;lt;build&amp;gt;
                &amp;lt;finalName&amp;gt;test-api-lib&amp;lt;/finalName&amp;gt;
            &amp;lt;/build&amp;gt;
        &amp;lt;/profile&amp;gt;
    &amp;lt;/profiles&amp;gt;

    &amp;lt;build&amp;gt;
        &amp;lt;finalName&amp;gt;${project.artifactId}&amp;lt;/finalName&amp;gt;
        &amp;lt;plugins&amp;gt;
            &amp;lt;plugin&amp;gt;
                &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
                &amp;lt;artifactId&amp;gt;maven-compiler-plugin&amp;lt;/artifactId&amp;gt;
                &amp;lt;version&amp;gt;3.8.1&amp;lt;/version&amp;gt;
                &amp;lt;configuration&amp;gt;
                    &amp;lt;source&amp;gt;1.8&amp;lt;/source&amp;gt;
                    &amp;lt;target&amp;gt;1.8&amp;lt;/target&amp;gt;
                &amp;lt;/configuration&amp;gt;
            &amp;lt;/plugin&amp;gt;
            &amp;lt;plugin&amp;gt;
               &amp;lt;groupId&amp;gt;org.apache.maven.plugins&amp;lt;/groupId&amp;gt;
               &amp;lt;artifactId&amp;gt;maven-install-plugin&amp;lt;/artifactId&amp;gt;
            &amp;lt;/plugin&amp;gt;
        &amp;lt;/plugins&amp;gt;
    &amp;lt;/build&amp;gt;
&amp;lt;/project&amp;gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;To build using these profiles we use the -P parameter with the profile id as below:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mvn install -P generate-library


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

mvn install -P generate-war


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Also if you are using intellij Idea then you can use the plugin as well to select the profile.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fst0zta5iahy35q74cmsx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fst0zta5iahy35q74cmsx.png" alt="Maven Build with Profiles in Intellij IDEA"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hope this helps you if you ever face such a scenario!&lt;/p&gt;

</description>
      <category>maven</category>
      <category>programming</category>
      <category>java</category>
      <category>springboot</category>
    </item>
    <item>
      <title>Efficient API Testing using Postman: Collections</title>
      <dc:creator>Ankit Yadav</dc:creator>
      <pubDate>Mon, 18 Dec 2023 14:01:19 +0000</pubDate>
      <link>https://dev.to/ankityadav33/efficient-api-testing-using-postman-collections-3ape</link>
      <guid>https://dev.to/ankityadav33/efficient-api-testing-using-postman-collections-3ape</guid>
      <description>&lt;p&gt;&lt;strong&gt;Postman&lt;/strong&gt; is an API platform for building and using APIs.&lt;/p&gt;

&lt;p&gt;It offers various features that are useful for both developers and testers. One of the core features is Collections to store all your API requests. &lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Collection&lt;/strong&gt; represents a group of requests that are grouped by some criteria (some of them are discussed below).&lt;/p&gt;

&lt;p&gt;The reason I am writing this specific post is because I have seen a lot of developers just putting in their requests randomly in the Postman, without any structure. So, when you need any specific request in the future, it takes ages to just get a working request from your existing Collections. &lt;br&gt;
Also, these collections cannot be used by anyone other than the one who created them as no one will be able to understand what the requests mean or represent.&lt;/p&gt;

&lt;p&gt;Here I am going to discuss about some basics of collections and how you can manage your postman collections, so that it is structured. To help you save time and create a sharable collection.&lt;/p&gt;

&lt;h2&gt;
  
  
  Criteria to arrange your collections
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Domain Driven Design&lt;/strong&gt; - As the name suggests, since most of the API will themselves be using the DDD, this can be a good starting point.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Along the lines of business&lt;/strong&gt; - A company’s products and services have evolved over time and can point to patterns and standards that can help define your APIs and organization structure.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Team Centered Approach&lt;/strong&gt; - Each team has its own collection.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Resource-Centered View&lt;/strong&gt; - A lot of effort is already put into the API paths and schemas, the same can be used to groups requests into collections. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Focusing On Collaboration&lt;/strong&gt; - If there are groups of requests that you would like to share with other team members, or open as public API, or some other restrictions, you can create collections for each of those groups.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Identifying your own approach&lt;/strong&gt; - If you have some other approach that better suits your requirements like versioning, stages, governance, chose that.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;An overview of Collections organised correctly, will help new team members get an overview of the complete application as well.&lt;/p&gt;




&lt;p&gt;Let's see how you can manage your collections, once you have identified a criteria to organise. Here are some of the ways I have  used myself.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;u&gt;&lt;em&gt;Workspace&lt;/em&gt;&lt;/u&gt;
&lt;/h3&gt;

&lt;p&gt;I have multiple workspaces based on the team/project I am working on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A workspace for each Completed Project&lt;/li&gt;
&lt;li&gt;Workspaces which I share with other people&lt;/li&gt;
&lt;li&gt;My personal workspace for POC or things not relevant to any project, but my personal learnings.&lt;/li&gt;
&lt;li&gt;A current in progress workspace for the project I am currently working on&lt;/li&gt;
&lt;li&gt;An archive workspace to move all old API to it, when I feel it is not required right now but might be required later.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;&lt;u&gt;Collections&lt;/u&gt;&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;Some of the approaches that I have used for collections are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Each project has its own collection&lt;/li&gt;
&lt;li&gt;A sharable read only public collection for different teams to get data using our API&lt;/li&gt;
&lt;li&gt;Collections based on Release targets&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;&lt;u&gt;Folders&lt;/u&gt;&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F113lk4twdcb3islve75a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F113lk4twdcb3islve75a.png" alt="Image showing folders inside a collection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Folders can be used to groups requests inside a collection. Some of the folder structures that I have used are based on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stories&lt;/li&gt;
&lt;li&gt;Resource paths&lt;/li&gt;
&lt;li&gt;API&lt;/li&gt;
&lt;li&gt;features&lt;/li&gt;
&lt;li&gt;Application pages&lt;/li&gt;
&lt;li&gt;Requests that are interdependent and might require to use data from each other&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;&lt;u&gt;Requests&lt;/u&gt;&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9qss13imby5lmpb73fx0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9qss13imby5lmpb73fx0.png" alt="Image showing list of request"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Almost all request variations are kept inside its own folder. The folder would have requests as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;GET Requests&lt;/li&gt;
&lt;li&gt;POST Requests&lt;/li&gt;
&lt;li&gt;PUT Requests&lt;/li&gt;
&lt;li&gt;DELETE requests &lt;/li&gt;
&lt;li&gt;any other request type&lt;/li&gt;
&lt;li&gt;Different variations of these requests based on different paths&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;&lt;u&gt;Examples&lt;/u&gt;&lt;/em&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F08k93nhexbvg4s7qtt6e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F08k93nhexbvg4s7qtt6e.png" alt="Image showing examples saved for a request"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is also a feature of examples which can be used to store the executed specific scenario. This includes: complete request with the request body &amp;amp; complete response details.&lt;br&gt;
Each request will have at least one of the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;working success scenario&lt;/li&gt;
&lt;li&gt;Failure(error) scenario&lt;/li&gt;
&lt;li&gt;only mandatory fields request scenario&lt;/li&gt;
&lt;li&gt;all fields request scenario&lt;/li&gt;
&lt;li&gt;Specific business scenarios&lt;/li&gt;
&lt;li&gt;Any Complex Bug related scenarios&lt;/li&gt;
&lt;li&gt;Response from different environments(Local, Dev, Staging, etc..)&lt;/li&gt;
&lt;li&gt;Anything else that you think will save time or you would require reference to in future.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Benefits of managing your collections in a structured way
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Easier to find specific requests&lt;/li&gt;
&lt;li&gt;One click to run complete set of requests in a folder/Collection&lt;/li&gt;
&lt;li&gt;Common authorization for all the requests in a folder/Collection&lt;/li&gt;
&lt;li&gt;Common pre-request scripts for a folder/Collection&lt;/li&gt;
&lt;li&gt;Common tests can be run on the run response for a folder/Collection&lt;/li&gt;
&lt;li&gt;Common variables can be managed and used through a Collection&lt;/li&gt;
&lt;li&gt;Can create a fork of a collections so that everyone can use the base collection as reference and making their own changes on it, also creating a Pull request, pulling changes added by other, maintain history for all changes.&lt;/li&gt;
&lt;li&gt;View Changelog for a collection&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Please do share your suggestions, that will help others improve productivity with Postman API testing.&lt;/p&gt;

</description>
      <category>postman</category>
      <category>api</category>
      <category>testing</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Standardize code formatting with Spotless</title>
      <dc:creator>Ankit Yadav</dc:creator>
      <pubDate>Sun, 31 Jul 2022 17:05:00 +0000</pubDate>
      <link>https://dev.to/ankityadav33/standardize-code-formatting-with-spotless-2bdh</link>
      <guid>https://dev.to/ankityadav33/standardize-code-formatting-with-spotless-2bdh</guid>
      <description>&lt;p&gt;Organizing and formatting code as a standard for the whole team is important and useful. Without a standard being followed for formatting code within the project following problems:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conflicts during updates from repository and during merge&lt;/li&gt;
&lt;li&gt;Developers using their preferred formatting&lt;/li&gt;
&lt;li&gt;Different auto format settings in IDEA showing more changes as when committing code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In order to setup a standard in regards to code formatting, we need to setup either a common configuration file to be imported by everyone or we can use something like Spotless which could be configured to use existing code formatting standards including Google Java Format and others.&lt;/p&gt;

&lt;p&gt;Spotless is available for lots of languages like: Java, Groovy, Kotlin, Scala, C/C++, Python, Sql, Typescript &lt;/p&gt;




&lt;p&gt;Here I am going to explain the usage of Spotless which we are using in our applications.&lt;/p&gt;

&lt;p&gt;The setup is really simple and comprises of only two steps no matter you use Maven or Gradle:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Include the spotless dependency: "com.diffplug.spotless"&lt;/li&gt;
&lt;li&gt;Configure the plugin based on what your formatting preferences&lt;/li&gt;
&lt;li&gt;Make it part of build (optional but preferred) &lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Include the spotless dependency
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Maven&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;dependency&amp;gt;
    &amp;lt;groupId&amp;gt;com.diffplug.spotless&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spotless-maven-plugin&amp;lt;/artifactId&amp;gt;
&amp;lt;/dependency&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Gradle&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies {
    implementation("com.diffplug.spotless:spotless-lib:${spotlessLibVersion}")
    implementation("com.diffplug.spotless:spotless-plugin-gradle:${spotlessVersion}")
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure the plugin
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Maven&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;plugin&amp;gt;
    &amp;lt;groupId&amp;gt;com.diffplug.spotless&amp;lt;/groupId&amp;gt;
    &amp;lt;artifactId&amp;gt;spotless-maven-plugin&amp;lt;/artifactId&amp;gt;
    &amp;lt;configuration&amp;gt;
        &amp;lt;ratchetFrom&amp;gt;origin/develop&amp;lt;/ratchetFrom&amp;gt;
        &amp;lt;java&amp;gt;
            &amp;lt;includes&amp;gt;
                &amp;lt;include&amp;gt;src/main/java/**/*.java&amp;lt;/include&amp;gt;
                &amp;lt;include&amp;gt;src/test/java/**/*.java&amp;lt;/include&amp;gt;
            &amp;lt;/includes&amp;gt;
            &amp;lt;importOrder /&amp;gt;
            &amp;lt;removeUnusedImports /&amp;gt;
            &amp;lt;toggleOffOn/&amp;gt;
            &amp;lt;trimTrailingWhitespace/&amp;gt;
            &amp;lt;endWithNewline/&amp;gt;
            &amp;lt;indent&amp;gt;
                &amp;lt;tabs&amp;gt;true&amp;lt;/tabs&amp;gt;
                &amp;lt;spacesPerTab&amp;gt;4&amp;lt;/spacesPerTab&amp;gt;
            &amp;lt;/indent&amp;gt;
            &amp;lt;palantirJavaFormat/&amp;gt;
        &amp;lt;/java&amp;gt;
    &amp;lt;/configuration&amp;gt;
&amp;lt;/plugin&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Gradle&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;spotless {
    java {
        target fileTree('.') {
            include '**/*.java'
            exclude '**/build/**', '**/build-*/**'
        }
        toggleOffOn()
        palantirJavaFormat()
        removeUnusedImports()
        trimTrailingWhitespace()
        endWithNewline()
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Common configurations used in the above example for formatting
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;importOrder&lt;/strong&gt;- All imports are ordered&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;removeUnusedImports&lt;/strong&gt; - Unused imports are removed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;toggleOffOn&lt;/strong&gt; - toggle formatting in code by a comment&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;trimTrailingWhitespace&lt;/strong&gt; - All trailing whitespaces in the code are removed&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;endWithNewline&lt;/strong&gt; - The file ends with a new line&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Execute spotless on code
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Maven&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;mvn spotless:apply - To implement automated code formatting&lt;br&gt;
 mvn spotless:check - To validate if code was formatted&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Gradle&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;.\gradlew clean build spotlessApply - To implement automated code formatting&lt;br&gt;
 .\gradlew clean build spotlessCheck - To validate if code was formatted​​​​​​​&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reference&lt;/strong&gt;: &lt;a href="https://github.com/diffplug/spotless"&gt;Github/spotless&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>codequality</category>
      <category>spotless</category>
    </item>
  </channel>
</rss>
