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.
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.
- 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.
-
Offers a small set of tasks:
assessCommon
: checks all the specified files with the Common Checkstyle's set from base-style-config project.assessGradle
: checks all the Gradle files (.gradle
) from the specified file tree with Codenarc's set from base-style-config project.- Task automatically filters the received file tree to get the
.gradle
files.
- Task automatically filters the received file tree to get the
-
Adds Tasks that show a summary of the CodeNarc report to console:
logForAssessGradle
[1].logForCodeNarcMain
[2].logForCodeNarcTest
[2].
-
Applies the required plugins to the project:
- Base Style Configuration Wrapper plugin.
- which will set some default configuration the Coding Style Tools.
- File Lister plugin .
- Checkstyle plugin.
- CodeNarc plugin.
- Base Style Configuration Wrapper plugin.
-
Allows to indicate the version of:
[1] Fails for exactly Gradle version 5.2, use any version (after or before) except 5.2.
[2] Added if thecodenarcMain
and/orcodenarcTest
tasks are present in the project.
- None
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.
2 . If required, use the plugin's extension, projectStyleChecker
, which have two fields [1]:
common
: has theassessCommon
configuration.gradle
: has theassessGradle
configuration.
Both have same fields:
config
: which correspond with theconfig
field ofCodeNarc task
orCheckstyle task
, basically the Code style set of rules.- By default, use rules defined by Base Style Configuration Wrapper plugin.
fileTree
: which indicate the file tree to explore when checking.- By default, all file tree is checked, using default exclusions of File Lister plugin exclusions.
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
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.
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.
- But, should be set in order to be compatible with the selected,
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.
- But, should be set in order to be compatible with the selected,
CODENARC_VERSION=1.3
- 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
.
Clone or download the project[1], in the desired folder execute:
git clone https://github.com/gmullerb/project-style-checker
- No need, only download and run (It's Gradle! Yes!).
- Remove the Git Origin:
git remote remove origin
. - Add your Git origin:
git remote add origin https://gitlab.com/yourUser/yourRepo.git
. - Remove the License for 'All rights reserved' projects, or Modify the License for your needs.
- Change the
all.shared.gradle.project-style-checker.properties
file name to your plugin Id, e.g.some.pluginId.properties
.
-
To build it:
gradlew
: this will run default task, orgradlew 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
/src
/main
/groovy
/test
/groovy
src/main/groovy
: Source code files.CreateAssessCommonAction
+PrepareAssessCommonAction
define theassessCommon
task.CreateAssessGradleAction
+PrepareAssessGradleAction
define theassessGradle
task.LogCodeNarcReportAction
is the action for logging report of a CodeNarc task.ProjectStyleChecker
is where all the magic happens (where plugins are added, where tasks are added, etc.).- If using this class directly, then prefer
fillAllExtensions
, overfillExtensionConfigs
,fillExtensionFileTree
,establishCheckstyleVersion
&establishCodenarcSettings
, seeProjectStyleCheckerPlugin
- If using this class directly, then prefer
src/test/groovy
: Test code files[1].
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.
- this methods is exactly equivalent to the instance
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.
CHANGELOG.md
: add information of notable changes for each version here, chronologically ordered [1].
[1] Keep a Changelog
- 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.
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.