Skip to content

Gradle plugin to create a clean application in Java that already works, It follows our best practices!

License

Notifications You must be signed in to change notification settings

juanpmarin/scaffold-clean-architecture

 
 

Repository files navigation

Quality Gate Status Maintainability Rating codecov GitHub license

Scaffolding of Clean Architecture

Gradle plugin to create a java application based on Clean Architecture following our best practices!

Plugin Implementation

To use the plugin you need Gradle version 5.6 or later, to start add the following section into your build.gradle file.

plugins {
    id "co.com.bancolombia.cleanArchitecture" version "1.8.8"
}

Tasks

The Scaffolding Clean Architecture plugin will allow you run 8 tasks:

Generate Project

  1. The cleanArchitecture | ca task will generate a clean architecture structure in your project, this task has four optional parameters; package , type, name and coverage.

    • package = <package.we.need>: You can specify the main or default package of your project. Default Value = co.com.bancolombia

    • type = <imperative | reactive>: With this parameter the task will generate a POO project. Default Value = imperative

    • name = NameProject: This parameter is going to specify the name of the project. Default Value = cleanArchitecture

    • coverage = <jacoco | cobertura>: This parameter is going to specify the coverage tool for the project. Default Value = jacoco

    • lombok = <true | false>: Specify if you want to use this plugin . Default Value = true

    gradle cleanArchitecture --package=co.com.bancolombia --type=imperative --name=NameProject --coverage=jacoco --lombok=true
    gradle ca --package=co.com.bancolombia --type=imperative --name=NameProject --coverage=jacoco --lombok=true

    The structure will look like this:

    📦NameProject
    ┣ 📂applications
    ┃ ┗ 📂app-service
    ┃ ┃ ┣ 📂src
    ┃ ┃ ┃ ┣ 📂main
    ┃ ┃ ┃ ┃ ┣ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂config
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜[configs and beans]
    ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜MainApplication.java
    ┃ ┃ ┃ ┃ ┗ 📂resources
    ┃ ┃ ┃ ┃ ┃ ┣ 📜[properties]
    ┃ ┃ ┃ ┗ 📂test
    ┃ ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┗ 📜build.gradle
    ┣ 📂deployment
    ┃ ┣ 📜[Dockerfile, Pipelines as a code]
    ┣ 📂domain
    ┃ ┣ 📂model
    ┃ ┃ ┣ 📂src
    ┃ ┃ ┃ ┣ 📂main
    ┃ ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┗ 📂test
    ┃ ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┗ 📜build.gradle
    ┃ ┗ 📂usecase
    ┃ ┃ ┣ 📂src
    ┃ ┃ ┃ ┣ 📂main
    ┃ ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┗ 📂test
    ┃ ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂usecase
    ┃ ┃ ┗ 📜build.gradle
    ┣ 📂infrastructure
    ┃ ┣ 📂driven-adapters
    ┃ ┣ 📂entry-points
    ┃ ┗ 📂helpers
    ┣ 📜.gitignore
    ┣ 📜build.gradle
    ┣ 📜gradle.properties
    ┣ 📜lombok.config
    ┣ 📜main.gradle
    ┣ 📜README.md
    ┗ 📜settings.gradle

Generate Model

  1. The generateModel | gm task will generate a class and interface in model layer, this task has one required parameter name.

    gradle generateModel --name=[modelName]
    gradle gm --name [modelName]

    This task will generate something like that:

    📦domain
    ┣ 📂model
    ┃ ┣ 📂src
    ┃ ┃ ┣ 📂main
    ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┗ 📂model
    ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂gateways
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜ModelRepository.java
    ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜Model.java
    ┃ ┃ ┗ 📂test
    ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┗ 📂model
    ┃ ┗ 📜build.gradle

Generate Use Case

  1. The generateUseCase | guc task will generate a class in model layer, this task has one required parameter name.

    gradle generateUseCase --name=[useCaseName]
    gradle guc --name [useCaseName]

    This task will generate something like that:

    📦domain
    ┗ 📂usecase
    ┃ ┣ 📂src
    ┃ ┃ ┣ 📂main
    ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┗ 📂usecase
    ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂business
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜BusinessUseCase.java
    ┃ ┃ ┗ 📂test
    ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┗ 📂usecase
    ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂business
    ┃ ┗ 📜build.gradle

Generate Driven Adapter

  1. The generateDrivenAdapter | gda task will generate a class in Infrastructure layer, this task has one required parameter type.
    Whether you'll use generic one also parameter name is required.

    gradle generateDrivenAdapter --type=[drivenAdapterType]
    gradle gda --type [drivenAdapterType]
    Reference for drivenAdapterType Name Additional Options
    generic Empty Driven Adapter --name [name]
    jpa JPA Repository --secret [true-false]
    mongodb Mongo Repository --secret [true-false]
    asynceventbus Async Event Bus
    restconsumer Rest Client Consumer --url [url]
    redis Redis --mode [template-repository] --secret [true-false]
    rsocket Rsocket Requester
    r2dbc R2dbc Postgresql Client
    kms AWS Key Management Service
    secrets Secrets Manager Bancolombia

    This task will generate something like that:

    📦infrastructure
    ┣ 📂driven-adapters
    ┃ ┗ 📂jpa-repository
    ┃ ┃ ┣ 📂src
    ┃ ┃ ┃ ┣ 📂main
    ┃ ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂jpa
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂config
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜DBSecret.java
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📂helper
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜AdapterOperations.java
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┣ 📜JPARepository.java
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📜JPARepositoryAdapter.java
    ┃ ┃ ┃ ┗ 📂test
    ┃ ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂jpa
    ┃ ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂helper
    ┃ ┃ ┗ 📜build.gradle

Generate Entry Point

  1. The generateEntryPoint | gep task will generate a class in Infrastructure layer, this task has one required parameter type.
    Whether you'll use generic one also parameter name is required.

    gradle generateEntryPoint --type=[entryPointType]
    gradle gep --type [entryPointType]
    Reference for entryPointType Name Additional Options
    generic Empty Entry Point --name [name]
    restmvc API REST (Spring Boot Starter Web) --server [serverOption] default undertow
    webflux API REST (Spring Boot Starter WebFlux) --router [true, false] default true
    rsocket Rsocket Controller Entry Point
    graphql API GraphQL --pathgql [name path] default /graphql
    asynceventhandler Async Event Handler

    Additionally, if you'll use a restmvc, you can specify the web server on which the application will run. By default, undertow.

    gradle generateEntryPoint --type=restmvc --server=[serverOption]
    gradle gep --type=restmvc --server=[serverOption]
    Reference for serverOption Name
    undertow Undertow server (default)
    tomcat Tomcat server
    jetty Jetty server

    This task will generate something like that:

    📦infrastructure
    ┣ 📂entry-points
    ┃ ┗ 📂generic
    ┃ ┃ ┣ 📂src
    ┃ ┃ ┃ ┣ 📂main
    ┃ ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂generic
    ┃ ┃ ┃ ┗ 📂test
    ┃ ┃ ┃ ┃ ┗ 📂java
    ┃ ┃ ┃ ┃ ┃ ┗ 📂[package]
    ┃ ┃ ┃ ┃ ┃ ┃ ┗ 📂generic
    ┃ ┃ ┗ 📜build.gradle

Validate Structure

  1. The validateStructure | vs Validate that project references aren't violated.

    gradle validateStructure
    gradle vs

Generate Pipeline

  1. The generatePipeline | gpl task will generate CI pipeline inside the folder "./deployment/", this task has one required parameter type.

    gradle generatePipeline --type=[pipelineType]
    gradle gpl --type=[pipelineType]
    Reference for pipelineType Name
    azure Azure Pipeline
    github GitHub Action

Delete Module

  1. The deleteModule | dm task will delete a sub project, this task has one required parameter module.

    gradle deleteModule --module=[name]
    gradle dm --module=[name]




How can I help?

Review the issues, we hear new ideas. Read more Contributing



Whats Next?

Read more About Clean Architecure

About

Gradle plugin to create a clean application in Java that already works, It follows our best practices!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 66.5%
  • Mustache 33.5%