Skip to content

hmtmcse-com/gradle-boilerplate-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gradle Boilerplate Project

Project Branches

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. :)

  1. master : Master Branch Consist with all branches Implementations
  2. git-source-dependency-clone : How to clone git source using gradle?
  3. gradle-upgrade-4-to-5: How to upgrade gradle version 4 to version 5
  4. 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



settings.gradle

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





build.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'
}

Full Source of build.gradle



Reference

  1. 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

  1. --gradle-version xx could be anything. for instance --gradle-version 7.0



Reference

  1. Gradle Upgrade: https://docs.gradle.org/current/userguide/upgrading_version_4.html
  2. 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

  1. form : This Closure telling gradle to what's are need to include into .jar file. It will include all dependency
  2. manifest : Meta Description of a jar file.
  3. destinationDirectory : output directory
  4. archivesBaseName : jar name



Reference

  1. Java Manifest Documentations : https://docs.oracle.com/javase/tutorial/deployment/jar/manifestindex.html
  2. Gradle Jar properties : https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html
  3. Gradle Build Java Libraries : https://guides.gradle.org/building-java-libraries/

Releases

No releases published

Packages

No packages published

Languages