Saturday, April 29, 2023

Gradle Basics

How to create a new gradle project? 

Pre-requisites:

  •  Java
  • Gradle

Steps

  • Create a folder using command
    • mkdir myproject
  • Go inside the folder
    • cd myproject
  • Run command 
    • gradle init
    • Select type as application
    • Select language as java
    • Select build script as Kotlin
    • Select Unit Test Framework as Junit Jupiter

Different files in gradle project

  • settings.gradle.kts

    • This is used to define the repositories under
      • dependencyResolutionManagement
      • pluginManagement
    • This is used set the project name and include sub projects
      • rootProject.name={Name of the project}
      • include("app") Name of all the subprojects to be included

  • build.gradle.sts

    • This is the build script for particular project
    • It has below sections
      • plugins - We can add different type of plugins 
        • e.g core plugins
                                        plugins{ 
                                            core
                                        }
                                        plugins { 
                                             id ("com.abc.xyz") version "1.0.0"
                                        }
      • repositories: Add repositories
                                        repositories{ 
                                            mavenCentral()
                                            mavenLocal()
                                            gradlePluginPortal()
                                            maven{
                                                url = uri("https://repo.com")
                                                artifactsUrls("https://mycom.com")
                                            }
                                        }
      • dependencies: Add dependencies
                                        dependencies{ 
                                               implementation("groupid:artifactId:version")
                                               testImplementation("groupid:artifactId:version")
                                        }
      • application: Set the main class for the project
                                        application{ 
                                               mainClass.set("abc.Main")
                                        }
      • tasks: Create a gradle task e.g. copy task would be like
                                        tasks.register<Copy>("myCustomTask"){ 
                                               from(file("abc.Main"))
                                               into(file("xyz.txt"))
                                        }


                                                

No comments:

Post a Comment

SpringBoot Application Event Listeners

When a spring boot application starts few events occurs in below order ApplicationStartingEvent ApplicationEnvironmentPreparedEvent Applicat...