blob: dbc8f5119a1fa70a34ae4232dad8e7d6d4358a0e [file] [log] [blame]
Manu Sridharan88bdd4a2017-08-15 14:30:41 -07001/*
2 * Copyright (C) 2017. Uber Technologies
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Thomas Broyer2cf80112018-10-17 21:19:38 +020017import net.ltgt.gradle.errorprone.CheckSeverity
Manu Sridharane43fc1e2020-02-13 12:34:00 -080018buildscript {
19 repositories {
Lázaro Clapp0c27e892021-03-30 20:07:07 -040020 mavenCentral()
Manu Sridharane43fc1e2020-02-13 12:34:00 -080021 google() // For Gradle 4.0+
22 }
Thomas Broyer2cf80112018-10-17 21:19:38 +020023
Manu Sridharane43fc1e2020-02-13 12:34:00 -080024 dependencies {
Manu Sridharan658819f2021-05-18 13:02:21 -070025 classpath 'com.android.tools.build:gradle:4.1.1'
Lázaro Clapp0c27e892021-03-30 20:07:07 -040026 classpath 'com.vanniktech:gradle-maven-publish-plugin:0.14.2'
Manu Sridharane43fc1e2020-02-13 12:34:00 -080027 }
28}
Manu Sridharanb4daf462017-09-26 14:03:26 -070029plugins {
Manu Sridharan658819f2021-05-18 13:02:21 -070030 id "com.github.sherter.google-java-format" version "0.9"
31 id "net.ltgt.errorprone" version "2.0.1" apply false
Lázaro Clapp0f12ab02021-04-08 20:09:18 -040032 id "com.github.johnrengelman.shadow" version "6.1.0" apply false
Manu Sridharan04e029a2021-12-23 14:08:12 -080033 id "com.github.kt3k.coveralls" version "2.12.0" apply false
Lázaro Clappeed3fc02021-01-05 14:27:41 -050034 id "com.android.application" version "3.5.0" apply false
Manu Sridharan6af3cfb2021-12-22 14:56:41 -080035 id "me.champeau.jmh" version "0.6.6" apply false
Manu Sridharanb4daf462017-09-26 14:03:26 -070036}
37
38repositories {
39 // to get the google-java-format jar and dependencies
Manu Sridharandba4c2d2021-05-03 16:52:10 -070040 mavenCentral()
Manu Sridharanb4daf462017-09-26 14:03:26 -070041}
42
Thomas Broyer2cf80112018-10-17 21:19:38 +020043apply from: "gradle/dependencies.gradle"
44
Manu Sridharan4c188132018-08-21 21:15:57 -070045subprojects { project ->
Thomas Broyer2cf80112018-10-17 21:19:38 +020046 project.apply plugin: "net.ltgt.errorprone"
47 project.dependencies {
48 errorprone deps.build.errorProneCore
49 errorproneJavac deps.build.errorProneJavac
Manu Sridharan4c188132018-08-21 21:15:57 -070050 }
Thomas Broyer2cf80112018-10-17 21:19:38 +020051 project.tasks.withType(JavaCompile) {
Lázaro Clapp8f06f382019-04-05 12:48:54 -040052 dependsOn(installGitHooks)
Thomas Broyer2cf80112018-10-17 21:19:38 +020053 options.compilerArgs += [
Lázaro Clappbf3de0f2020-06-24 12:38:46 -040054 "-Xlint:deprecation",
Thomas Broyer2cf80112018-10-17 21:19:38 +020055 "-Xlint:rawtypes",
Lázaro Clappbf3de0f2020-06-24 12:38:46 -040056 "-Xlint:unchecked",
Thomas Broyer2cf80112018-10-17 21:19:38 +020057 "-Werror"
58 ]
59 options.errorprone {
60 // disable warnings in generated code; AutoValue code fails UnnecessaryParentheses check
61 disableWarningsInGeneratedCode = true
Lázaro Clappbf3de0f2020-06-24 12:38:46 -040062 // Triggers for generated Android code (R.java)
63 check("MutablePublicArray", CheckSeverity.OFF)
Thomas Broyer2cf80112018-10-17 21:19:38 +020064 // this check is too noisy
65 check("StringSplitter", CheckSeverity.OFF)
66 check("WildcardImport", CheckSeverity.ERROR)
Manu Sridharanb27c6e12022-01-18 12:47:47 -080067 check("MissingBraces", CheckSeverity.ERROR)
Manu Sridharan88bdd4a2017-08-15 14:30:41 -070068 }
69 }
70
Manu Sridharanf1a87512018-12-03 18:30:29 -080071 if (JavaVersion.current().java9Compatible) {
72 tasks.withType(JavaCompile) {
Manu Sridharandf1369e2021-12-09 10:17:10 -080073 options.release = 8
Manu Sridharanf1a87512018-12-03 18:30:29 -080074 }
75 }
76
Jiahe Gellert Li55de3a82022-01-15 15:00:48 -080077 tasks.withType(Test).configureEach {
78 maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
79 }
80
Manu Sridharan88bdd4a2017-08-15 14:30:41 -070081 repositories {
Manu Sridharandba4c2d2021-05-03 16:52:10 -070082 mavenCentral()
Manu Sridharana08b2ed2017-12-11 08:58:54 -080083 google()
Manu Sridharan88bdd4a2017-08-15 14:30:41 -070084 }
85
86}
87
Manu Sridharanb4daf462017-09-26 14:03:26 -070088googleJavaFormat {
Manu Sridharan4c188132018-08-21 21:15:57 -070089 toolVersion = "1.6"
Manu Sridharan04e029a2021-12-23 14:08:12 -080090 // don't enforce formatting for generated Java code under buildSrc
91 exclude 'buildSrc/build/**/*.java'
Manu Sridharanb4daf462017-09-26 14:03:26 -070092}
Lázaro Clapp8f06f382019-04-05 12:48:54 -040093
94////////////////////////////////////////////////////////////////////////
95//
96// Google Java Format pre-commit hook installation
97//
98
99tasks.register('installGitHooks', Copy) {
100 from(file('config/hooks/pre-commit-stub')) {
101 rename 'pre-commit-stub', 'pre-commit'
102 }
103 into file('.git/hooks')
104 fileMode 0777
105}