This project based on multiple branch, each branch has specific Implementation, so if you want then you can switch branch for see the specific implementations. you may use diff for find out changes. :)
- master : Master Branch Consist with all branches Implementations
- git-source-dependency-clone : How to clone git source using gradle?
- gradle-upgrade-4-to-5: How to upgrade gradle version 4 to version 5
- java-jar-using-gradle: How do i make a executable / library jar using gradle?
How to create Gradle Project with git Source Dependency? YouTube Video Link
Project Git Branch: git-source-dependency-clone
Here we will going to use grgit gradle plugin let's follow the Steps
Add below codes into settings.gradle
rootProject.name = 'GradleBoilerplateProject'
File exRepositories = file('ex-plugins/')
if (exRepositories.exists()){
exRepositories.list().each {
include(it)
project(":${it}").projectDir = file("ex-plugins/${it}")
}
}
Full Source of settings.gradle
Add below codes into build.gradle
plugins {
id 'java'
id "org.ajoberstar.grgit" version "3.1.1"
}
group 'com.hmtmcse.tool'
version '1.0'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
// All Git repository List
def repositoryMap = [
"java-common" : "https://github.com/hmtmcse/java-common.git",
]
// Clone Repository Task
task cloneRepositories {
doLast {
repositoryMap.each { name, url ->
println("------------------------------------------------------------------------------------------")
def destination = file("ex-plugins/${name}")
try{
println("Cloning Project ${name}")
org.ajoberstar.grgit.Grgit.clone(dir: destination, uri: url)
}catch(Exception e){
println(e.getMessage())
}
println("------------------------------------------------------------------------------------------\n")
}
}
}
dependencies {
// if external source repositories directory is available then add those as dependency
File exRepositories = file('ex-plugins/')
if (exRepositories.exists()){
exRepositories.list().each {
implementation project(":${it}")
}
}
testImplementation group: 'junit', name: 'junit', version: '4.12'
}
Reference
- Gradle grplugin: https://plugins.gradle.org/plugin/org.ajoberstar.grgit
How to Upgrade Gradle version 4 to Gradle Version 5? YouTube Video Link
Project Git Branch: gradle-upgrade-4-to-5
Run the belong command from Gradle source, before run command please make sure, you have gradle wrapper on your project and also the gradlew (For unix system), gradlew.bat (For Windows System) Available. These commands will not run if you haven't Java home set.
gradle wrapper --gradle-version 5.0
# For Windows and With Gradle Wrapper
gradlew.bat wrapper --gradle-version 5.0
# For Unix / Mac / Linux and With Gradle Wrapper
gradlew.bat wrapper --gradle-version 5.0
Here
- --gradle-version xx could be anything. for instance --gradle-version 7.0
Reference
- Gradle Upgrade: https://docs.gradle.org/current/userguide/upgrading_version_4.html
- Java Home Setup https://www.youtube.com/watch?v=qEk8Q-N4Hz4
How to Create Jar file using Gradle? YouTube Video Link
Project Git Branch: java-jar-using-gradle
Please add the below codes into your build.gradle file
jar {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes(
'Implementation-Title': 'Jar Making Exaple',
"Main-Class": "com.hmtmcse.tool.Bismillah"
)
}
destinationDirectory = file("$rootDir/my-jar")
archivesBaseName = 'app'
}
Here
- form : This Closure telling gradle to what's are need to include into .jar file. It will include all dependency
- manifest : Meta Description of a jar file.
- destinationDirectory : output directory
- archivesBaseName : jar name
Reference
- Java Manifest Documentations : https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
- Gradle Jar properties : https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html
- Gradle Build Java Libraries : https://guides.gradle.org/building-java-libraries/