|
| 1 | +buildscript { |
| 2 | + repositories { |
| 3 | + mavenCentral() |
| 4 | + mavenLocal() |
| 5 | + maven { |
| 6 | + url "https://plugins.gradle.org/m2/" |
| 7 | + } |
| 8 | + } |
| 9 | + dependencies { |
| 10 | + classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.4.6' |
| 11 | + classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.0.16' |
| 12 | + classpath "net.ltgt.gradle:gradle-apt-plugin:0.18" |
| 13 | + classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0' |
| 14 | + classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8" |
| 15 | + classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.8" |
| 16 | + classpath "gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.9.0" |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +// Display the version report using: ./gradlew dependencyUpdates |
| 21 | +// Also see https://github.com/ben-manes/gradle-versions-plugin. |
| 22 | +apply plugin: 'com.github.ben-manes.versions' |
| 23 | + |
| 24 | +subprojects { |
| 25 | + apply plugin: "checkstyle" |
| 26 | + apply plugin: 'maven' |
| 27 | + apply plugin: 'idea' |
| 28 | + apply plugin: 'eclipse' |
| 29 | + apply plugin: 'java' |
| 30 | + apply plugin: "signing" |
| 31 | + apply plugin: "jacoco" |
| 32 | + // The plugin only has an effect if a signature is specified |
| 33 | + apply plugin: 'ru.vyarus.animalsniffer' |
| 34 | + apply plugin: 'findbugs' |
| 35 | + apply plugin: 'net.ltgt.apt' |
| 36 | + apply plugin: 'net.ltgt.apt-idea' |
| 37 | + apply plugin: "me.champeau.gradle.jmh" |
| 38 | + apply plugin: "io.morethan.jmhreport" |
| 39 | + apply plugin: 'com.github.sherter.google-java-format' |
| 40 | + apply plugin: "net.ltgt.errorprone" |
| 41 | + |
| 42 | + group = "io.openconsensus" |
| 43 | + version = "0.1.0-SNAPSHOT" // CURRENT_VERSION |
| 44 | + |
| 45 | + sourceCompatibility = 1.7 |
| 46 | + targetCompatibility = 1.7 |
| 47 | + |
| 48 | + repositories { |
| 49 | + mavenCentral() |
| 50 | + mavenLocal() |
| 51 | + } |
| 52 | + |
| 53 | + [compileJava, compileTestJava, compileJmhJava].each() { |
| 54 | + // We suppress the "try" warning because it disallows managing an auto-closeable with |
| 55 | + // try-with-resources without referencing the auto-closeable within the try block. |
| 56 | + // We suppress the "processing" warning as suggested in |
| 57 | + // https://groups.google.com/forum/#!topic/bazel-discuss/_R3A9TJSoPM |
| 58 | + it.options.compilerArgs += ["-Xlint:all", "-Xlint:-try", "-Xlint:-processing"] |
| 59 | + it.options.compilerArgs += ["-XepAllDisabledChecksAsWarnings", "-XepDisableWarningsInGeneratedCode"] |
| 60 | + |
| 61 | + // MutableMethodReturnType can suggest returning Guava types from |
| 62 | + // API methods (https://github.com/google/error-prone/issues/982). |
| 63 | + it.options.compilerArgs += ["-Xep:MutableMethodReturnType:OFF"] |
| 64 | + |
| 65 | + // Doesn't currently use Var annotations. |
| 66 | + it.options.compilerArgs += ["-Xep:Var:OFF"] |
| 67 | + |
| 68 | + // ImmutableRefactoring suggests using com.google.errorprone.annotations.Immutable, |
| 69 | + // but currently uses javax.annotation.concurrent.Immutable |
| 70 | + it.options.compilerArgs += ["-Xep:ImmutableRefactoring:OFF"] |
| 71 | + |
| 72 | + // This check causes a NullPointerException |
| 73 | + // (https://github.com/google/error-prone/issues/1138). |
| 74 | + it.options.compilerArgs += ["-Xep:NullableDereference:OFF"] |
| 75 | + |
| 76 | + // ExpectedExceptionRefactoring and TestExceptionRefactoring suggest using |
| 77 | + // assertThrows, but assertThrows only works well with lambdas. |
| 78 | + it.options.compilerArgs += ["-Xep:ExpectedExceptionRefactoring:OFF"] |
| 79 | + it.options.compilerArgs += ["-Xep:TestExceptionRefactoring:OFF"] |
| 80 | + it.options.encoding = "UTF-8" |
| 81 | + } |
| 82 | + |
| 83 | + compileTestJava { |
| 84 | + // serialVersionUID is basically guaranteed to be useless in tests |
| 85 | + options.compilerArgs += ["-Xlint:-serial"] |
| 86 | + // It undeprecates DoubleSubject.isEqualTo(Double). |
| 87 | + options.compilerArgs += ["-Xlint:-deprecation"] |
| 88 | + } |
| 89 | + |
| 90 | + jar.manifest { |
| 91 | + attributes('Implementation-Title': name, |
| 92 | + 'Implementation-Version': version, |
| 93 | + 'Built-By': System.getProperty('user.name'), |
| 94 | + 'Built-JDK': System.getProperty('java.version'), |
| 95 | + 'Source-Compatibility': sourceCompatibility, |
| 96 | + 'Target-Compatibility': targetCompatibility) |
| 97 | + } |
| 98 | + |
| 99 | + javadoc.options { |
| 100 | + encoding = 'UTF-8' |
| 101 | + links 'https://docs.oracle.com/javase/8/docs/api/' |
| 102 | + } |
| 103 | + |
| 104 | + ext { |
| 105 | + autoValueVersion = '1.4' |
| 106 | + findBugsAnnotationsVersion = '3.0.1' |
| 107 | + findBugsJsr305Version = '3.0.2' |
| 108 | + errorProneVersion = '2.3.2' |
| 109 | + grpcVersion = '1.18.0' |
| 110 | + guavaVersion = '26.0-android' |
| 111 | + |
| 112 | + libraries = [ |
| 113 | + auto_value: "com.google.auto.value:auto-value:${autoValueVersion}", |
| 114 | + auto_service: 'com.google.auto.service:auto-service:1.0-rc3', |
| 115 | + config: 'com.typesafe:config:1.2.1', |
| 116 | + errorprone: "com.google.errorprone:error_prone_annotations:${errorProneVersion}", |
| 117 | + findbugs_annotations: "com.google.code.findbugs:annotations:${findBugsAnnotationsVersion}", |
| 118 | + grpc_context: "io.grpc:grpc-context:${grpcVersion}", |
| 119 | + guava: "com.google.guava:guava:${guavaVersion}", |
| 120 | + jsr305: "com.google.code.findbugs:jsr305:${findBugsJsr305Version}", |
| 121 | + |
| 122 | + // Test dependencies. |
| 123 | + guava_testlib: "com.google.guava:guava-testlib:${guavaVersion}", |
| 124 | + junit: 'junit:junit:4.12', |
| 125 | + mockito: 'org.mockito:mockito-core:1.9.5', |
| 126 | + truth: 'com.google.truth:truth:0.42', |
| 127 | + ] |
| 128 | + } |
| 129 | + |
| 130 | + configurations { |
| 131 | + compile { |
| 132 | + // Detect Maven Enforcer's dependencyConvergence failures. We only |
| 133 | + // care for artifacts used as libraries by others. |
| 134 | + resolutionStrategy.failOnVersionConflict() |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + dependencies { |
| 139 | + compileOnly libraries.errorprone, |
| 140 | + libraries.jsr305 |
| 141 | + |
| 142 | + testCompile libraries.guava_testlib, |
| 143 | + libraries.junit, |
| 144 | + libraries.mockito, |
| 145 | + libraries.truth |
| 146 | + |
| 147 | + // The ErrorProne plugin defaults to the latest, which would break our |
| 148 | + // build if error prone releases a new version with a new check |
| 149 | + errorprone "com.google.errorprone:error_prone_core:${errorProneVersion}" |
| 150 | + } |
| 151 | + |
| 152 | + findbugs { |
| 153 | + toolVersion = findBugsAnnotationsVersion |
| 154 | + ignoreFailures = false // bug free or it doesn't ship! |
| 155 | + effort = 'max' |
| 156 | + reportLevel = 'low' // low = sensitive to even minor mistakes |
| 157 | + omitVisitors = [] // bugs that we want to ignore |
| 158 | + excludeFilter = file("$rootDir/findbugs-exclude.xml") |
| 159 | + } |
| 160 | + // Generate html report for findbugs. |
| 161 | + findbugsMain { |
| 162 | + reports { |
| 163 | + xml.enabled = false |
| 164 | + html.enabled = true |
| 165 | + } |
| 166 | + } |
| 167 | + findbugsTest { |
| 168 | + reports { |
| 169 | + xml.enabled = false |
| 170 | + html.enabled = true |
| 171 | + } |
| 172 | + } |
| 173 | + findbugsJmh { |
| 174 | + reports { |
| 175 | + xml.enabled = false |
| 176 | + html.enabled = true |
| 177 | + } |
| 178 | + } |
| 179 | + |
| 180 | + checkstyle { |
| 181 | + configFile = file("$rootDir/buildscripts/checkstyle.xml") |
| 182 | + toolVersion = "8.12" |
| 183 | + ignoreFailures = false |
| 184 | + if (rootProject.hasProperty("checkstyle.ignoreFailures")) { |
| 185 | + ignoreFailures = rootProject.properties["checkstyle.ignoreFailures"].toBoolean() |
| 186 | + } |
| 187 | + configProperties["rootDir"] = rootDir |
| 188 | + } |
| 189 | + |
| 190 | + googleJavaFormat { |
| 191 | + toolVersion '1.7' |
| 192 | + } |
| 193 | + |
| 194 | + afterEvaluate { // Allow subproject to add more source sets. |
| 195 | + tasks.googleJavaFormat { |
| 196 | + source = sourceSets*.allJava |
| 197 | + include '**/*.java' |
| 198 | + } |
| 199 | + |
| 200 | + tasks.verifyGoogleJavaFormat { |
| 201 | + source = sourceSets*.allJava |
| 202 | + include '**/*.java' |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + signing { |
| 207 | + required false |
| 208 | + sign configurations.archives |
| 209 | + } |
| 210 | + |
| 211 | + task javadocJar(type: Jar) { |
| 212 | + classifier = 'javadoc' |
| 213 | + from javadoc |
| 214 | + } |
| 215 | + |
| 216 | + task sourcesJar(type: Jar) { |
| 217 | + classifier = 'sources' |
| 218 | + from sourceSets.main.allSource |
| 219 | + } |
| 220 | + |
| 221 | + artifacts { |
| 222 | + archives javadocJar, sourcesJar |
| 223 | + } |
| 224 | + |
| 225 | + jmh { |
| 226 | + jmhVersion = '1.20' |
| 227 | + warmupIterations = 10 |
| 228 | + iterations = 10 |
| 229 | + fork = 1 |
| 230 | + failOnError = true |
| 231 | + resultFormat = 'JSON' |
| 232 | + // Allow to run single benchmark class like: |
| 233 | + // ./gradlew -PjmhIncludeSingleClass=StatsTraceContextBenchmark clean :grpc-core:jmh |
| 234 | + if (project.hasProperty('jmhIncludeSingleClass')) { |
| 235 | + include = [ |
| 236 | + project.property('jmhIncludeSingleClass') |
| 237 | + ] |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + jmhReport { |
| 242 | + jmhResultPath = project.file("${project.buildDir}/reports/jmh/results.json") |
| 243 | + jmhReportOutput = project.file("${project.buildDir}/reports/jmh") |
| 244 | + } |
| 245 | + |
| 246 | + tasks.jmh.finalizedBy tasks.jmhReport |
| 247 | + |
| 248 | + // At a test failure, log the stack trace to the console so that we don't |
| 249 | + // have to open the HTML in a browser. |
| 250 | + test { |
| 251 | + testLogging { |
| 252 | + exceptionFormat = 'full' |
| 253 | + showExceptions true |
| 254 | + showCauses true |
| 255 | + showStackTraces true |
| 256 | + } |
| 257 | + maxHeapSize = '1500m' |
| 258 | + } |
| 259 | +} |
0 commit comments