diff --git a/android/app/build.gradle b/android/app/build.gradle index 378dd030525..c3f7eb9c748 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -7,6 +7,7 @@ apply plugin: 'com.android.application' +// Set up Android app project. android { compileSdkVersion 29 defaultConfig { @@ -35,6 +36,18 @@ android { } } +// Checks our Java code against our style guidelines and for common coding mistakes using "checkstyle.xml". +// Will trigger a build failure if any violations have been detected. +task checkJavaStyle(type: Checkstyle) { + source android.sourceSets.main.java.srcDirs + include '**/*.java' + classpath = files() +} +tasks.withType(JavaCompile) { + dependsOn checkJavaStyle +} + +// Define library dependencies used by this app. dependencies { implementation(project(':titanium')) { // Uncomment the below to exclude Google Play Services from app. diff --git a/android/build.gradle b/android/build.gradle index ca04f15b356..155a78d6abb 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -23,6 +23,17 @@ allprojects { google() jcenter() } + + // Load plugin used to enforce our Java coding style guidelines. + project.apply plugin: 'checkstyle' + checkstyle { + toolVersion = '8.30' + configFile file("${rootDir}/checkstyle.xml"); + ignoreFailures false + showViolations true + } + + // Include Titanium's gradle constants in all gradle sub-projects. project.apply from: "${rootDir}/templates/build/ti.constants.gradle" } diff --git a/android/checkstyle.xml b/android/checkstyle.xml new file mode 100644 index 00000000000..2acf1c217c3 --- /dev/null +++ b/android/checkstyle.xml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android/kroll-apt/build.gradle b/android/kroll-apt/build.gradle index be6931121e8..ed1d0250e30 100644 --- a/android/kroll-apt/build.gradle +++ b/android/kroll-apt/build.gradle @@ -10,7 +10,19 @@ apply plugin: 'java' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 +// Checks our Java code against our style guidelines and for common coding mistakes using "checkstyle.xml". +// Will trigger a build failure if any violations have been detected. +task checkJavaStyle(type: Checkstyle) { + source 'src/main/java' + include '**/*.java' + classpath = files() +} + +// Hook into Java compile task. tasks.withType(JavaCompile) { + // Check Java code for mistakes before compiling. + dependsOn checkJavaStyle + // Suppress compiler warning "bootstrap class path not set in conjunction with source" which happens when // building with JDK newer than the Java version we're targeting. (Ex: Build with JDK 8, but target Java 7.) // Note: Build tool wants a reference to runtime JAR of the same version we're targeting. Not going to happen. diff --git a/package.json b/package.json index 8960e74b5b9..30b4d106125 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "ios-sanity-check": "./build/scons check-ios-toplevel", "link": "npm run deploy -- --symlink", "lint": "npm-run-all --parallel lint:**", - "lint:android": "clang-format-lint $npm_package_config_format_android", + "lint:android": "echo Disabled in favor of gradle checkstyle tool.", "lint:docs": "tdoc-validate ./apidoc", "lint:ios": "clang-format-lint $npm_package_config_format_ios", "lint:js": "eslint .", @@ -70,9 +70,6 @@ "iphone/TitaniumKit/TitaniumKit/Sources/API/TopTiModule.m": [ "npm run ios-sanity-check --" ], - "android/!(templates)/**/*.java": [ - "npx clang-format -style=file -i" - ], "!(**/locales/**/*).js": "eslint" }, "commitlint": {