Skip to content

gmullerb/project-style-checker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Style Checker

license Download coverage report

A Gradle plugin that offers a small set of Gradle's tasks for checking file style for all files and for checking code style of Gradle's build code.

This project is licensed under the terms of the MIT license.


Quick Start

1 . Apply the plugin:

build.gradle:

 plugins {
   id 'all.shared.gradle.project-style-checker' version '1.0.5'
 }

2 . Add assessCommon and assessGradle tasks, usually as default tasks:

build.gradle:

  defaultTasks 'assessCommon', 'assessGradle', ..

3 . Jump to Using/Configuration, for customization or digging on How it works.


Goals

  • Have a task for checking all files, not only code files, with some basic but common rules.
  • Have a task for checking Gradle's code.
  • Allow to log to console of checking report.
  • Automatically apply all the required plugins.

Features

[1] Fails for exactly Gradle version 5.2, use any version (after or before) except 5.2.
[2] Added if the codenarcMain and/or codenarcTest tasks are present in the project.


Using/Configuration

Prerequisites

  • None

Gradle configuration

1 . Apply the plugin [1]:

 plugins {
   id 'all.shared.gradle.project-style-checker' version '1.0.5'
 }

[1]: This is the only configuration step required to use this plugin.

Plugin configuration [Optional]

2 . If required, use the plugin's extension, projectStyleChecker, which have two fields [1]:

  • common: has the assessCommon configuration.
  • gradle: has the assessGradle configuration.

Both have same fields:

E.G.:

 projectStyleChecker {
   common {
     config = ..
     fileTree = ..
   }
   gradle {
     config = ..
     fileTree = ..
   }
 }

[1] All these values are filled by default with values obtain from Base Style Configuration Wrapper plugin and File Lister plugin

Code Quality Tools Configuration [Optional]

The following processes are inherited/done by the Base Style Configuration Wrapper plugin:

3 . Use BASE_STYLE_CONFIG_VERSION to establish the version of Base Style Configuration to be used:

  • If not set, then last version will be used.

gradle.properties:

 BASE_STYLE_CONFIG_VERSION=2.0.1

4 . Use CHECKSTYLE_VERSION to establish the version of Checkstyle to be used:

  • Use to check all files.
  • If not set, Gradle's default version will be used.
    • But, should be set in order to be compatible with the selected, BASE_STYLE_CONFIG_VERSION, i.e. with the selected set of rules defined by Base Style Configuration.

gradle.properties:

 CHECKSTYLE_VERSION=8.18

5 . Use CODENARC_VERSION to establish the version of CodeNarc to be used:

  • Use to check Gradle files.
  • If not set, Gradle's default version will be used.
    • But, should be set in order to be compatible with the selected, BASE_STYLE_CONFIG_VERSION, i.e. with the selected set of rules defined by Base Style Configuration.

gradle.properties:

 CODENARC_VERSION=1.3

Assessing files

  • To assess all files use Gradle task: assessCommon.
  • To assess Gradle's code use Gradle task: assessGradle.
  • To assess CodeNarc's code use Gradle task: codenarcMain.
  • To assess CodeNarc's code use Gradle task: codenarcTest.

Extending/Developing

Prerequisites

  • Java.
  • Git (only if you are going to clone the project).

Getting it

Clone or download the project[1], in the desired folder execute:

git clone https://github.com/gmullerb/project-style-checker

[1] Cloning a repository

Set up

  • No need, only download and run (It's Gradle! Yes!).

Make it your own

  1. Remove the Git Origin: git remote remove origin.
  2. Add your Git origin: git remote add origin https://gitlab.com/yourUser/yourRepo.git.
  3. Remove the License for 'All rights reserved' projects, or Modify the License for your needs.
  4. Change the all.shared.gradle.project-style-checker.properties file name to your plugin Id, e.g. some.pluginId.properties.

Building it

  • To build it:

    • gradlew: this will run default task, or
    • gradlew build.
  • To assess files:

    • gradlew assessCommon: will check common style of files.
    • gradlew assessGradle: will check code style of Gradle's.
    • gradlew codenarcMain: will check code style of Groovy's source files.
    • gradlew codenarcTest: will check code style of Groovy's test files.
    • assemble task depends on these four tasks.
  • To test code: gradlew test

  • To get all the tasks for the project: gradlew tasks --all

Folders structure

  /src
    /main
      /groovy
    /test
      /groovy

[1] Tests are done with JUnit and Mockito.

Convention over Configuration

All all.shared.gradle plugins define:

  • PluginNamePlugin: which contains the class implements Plugin interface.
  • PluginNameExtension: which represent the extension of the plugin.
  • If Tasks are define, then their names will be TaskNameTask.
  • If Actions are define, then their names will be ActionNameAction.

All all.shared.gradle plugins have two static members:

  • String EXTENSION_NAME: This will have the name of the extension that the plugin add.

    • if the plugin does not add an extension the this field will not exist.
  • String TASK_NAME: This will have the name of the unique task that the plugin add.

    • if the plugin does not add a task or add more than one task, then this field will not exist.
  • boolean complement(final ..): will apply the plugin and return true if successful, false otherwise.

    • this methods is exactly equivalent to the instance apply method, but without instantiate the class if not required.

Both may be useful when applying the plugin when creating custom plugins.

All all.shared.gradle plugins "silently" fail when the extension can not be added.

Documentation

  • CHANGELOG.md: add information of notable changes for each version here, chronologically ordered [1].

[1] Keep a Changelog

License

MIT License


Remember

  • Use code style verification tools => Encourages Best Practices, Efficiency, Readability and Learnability.
  • Start testing early => Encourages Reliability and Maintainability.
  • Code Review everything => Encourages Functional suitability, Performance Efficiency and Teamwork.

Additional words

Don't forget:

  • Love what you do.
  • Learn everyday.
  • Learn yourself.
  • Share your knowledge.
  • Learn from the past, dream on the future, live and enjoy the present to the max!.

At life:

  • Let's act, not complain.
  • Be flexible.

At work:

  • Let's give solutions, not questions.
  • Aim to simplicity not intellectualism.