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
core
}
plugins {
plugins {
id ("com.abc.xyz") version "1.0.0"
}
- repositories: Add repositories
mavenCentral()
mavenLocal()
gradlePluginPortal()
maven{
url = uri("https://repo.com")
artifactsUrls("https://mycom.com")
}
}
- dependencies: Add dependencies
implementation("groupid:artifactId:version")
testImplementation("groupid:artifactId:version")
}
- application: Set the main class for the project
mainClass.set("abc.Main")
}
- tasks: Create a gradle task e.g. copy task would be like
from(file("abc.Main"))
into(file("xyz.txt"))
}
No comments:
Post a Comment