Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor top-level build.gradle to avoid enabling unhelpful plugins #6131

Merged
merged 7 commits into from
Sep 13, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions all/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "com.github.kt3k.coveralls"
Expand Down
1 change: 1 addition & 0 deletions alts/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not move 'maven' plugin as well? If mavne-publish is a super set of maven plugin, we can remove maven plugin.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just assume delete the maven plugin. I couldn't find anything that failed when I removed the maven plugin outright. That seemed suspicious to me, so I just left it in place for now to reduce the risk.


id "com.github.johnrengelman.shadow"
Expand Down
1 change: 1 addition & 0 deletions api/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "me.champeau.gradle.jmh"
Expand Down
1 change: 1 addition & 0 deletions auth/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "me.champeau.gradle.japicmp"
Expand Down
1 change: 1 addition & 0 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "application"
id "java"
id "maven-publish"

id "com.google.protobuf"
Expand Down
181 changes: 97 additions & 84 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import net.ltgt.gradle.errorprone.CheckSeverity

subprojects {
apply plugin: "checkstyle"
apply plugin: "java"
apply plugin: "maven"
apply plugin: "idea"
apply plugin: "signing"
Expand All @@ -20,30 +19,10 @@ subprojects {
apply plugin: "ru.vyarus.animalsniffer"

apply plugin: "net.ltgt.errorprone"
if (rootProject.properties.get('errorProne', true)) {
dependencies {
errorprone 'com.google.errorprone:error_prone_core:2.3.3'
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'

annotationProcessor 'com.google.guava:guava-beta-checker:1.0'
}
} else {
// Disable Error Prone
allprojects {
afterEvaluate { project ->
project.tasks.withType(JavaCompile) {
options.errorprone.enabled = false
}
}
}
}

group = "io.grpc"
version = "1.24.0-SNAPSHOT" // CURRENT_GRPC_VERSION

sourceCompatibility = 1.7
targetCompatibility = 1.7

repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
Expand All @@ -63,31 +42,6 @@ subprojects {
}
}

compileTestJava {
// serialVersionUID is basically guaranteed to be useless in our tests
options.compilerArgs += [
"-Xlint:-serial"
]
// LinkedList doesn't hurt much in tests and has lots of usages
options.errorprone.check("JdkObsolete", CheckSeverity.OFF)
}

jar.manifest {
attributes('Implementation-Title': name,
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-JDK': System.getProperty('java.version'),
'Source-Compatibility': sourceCompatibility,
'Target-Compatibility': targetCompatibility)
}

javadoc.options {
encoding = 'UTF-8'
use = true
links 'https://docs.oracle.com/javase/8/docs/api/'
source = "8"
}

ext {
def exeSuffix = osdetector.os == 'windows' ? ".exe" : ""
protocPluginBaseName = 'protoc-gen-grpc-java'
Expand Down Expand Up @@ -233,12 +187,6 @@ subprojects {
}
}

dependencies {
testCompile libraries.junit,
libraries.mockito,
libraries.truth
}

// Disable JavaDoc doclint on Java 8. It's annoying.
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
Expand Down Expand Up @@ -268,12 +216,81 @@ subprojects {
}
}

checkstyleMain {
source = fileTree(dir: "src/main", include: "**/*.java")
}
plugins.withId("java") {
sourceCompatibility = 1.7
targetCompatibility = 1.7

dependencies {
testCompile libraries.junit,
libraries.mockito,
libraries.truth
}

compileTestJava {
// serialVersionUID is basically guaranteed to be useless in our tests
options.compilerArgs += [
"-Xlint:-serial"
]
}

jar.manifest {
attributes('Implementation-Title': name,
'Implementation-Version': version,
'Built-By': System.getProperty('user.name'),
'Built-JDK': System.getProperty('java.version'),
'Source-Compatibility': sourceCompatibility,
'Target-Compatibility': targetCompatibility)
}

javadoc.options {
encoding = 'UTF-8'
use = true
links 'https://docs.oracle.com/javase/8/docs/api/'
source = "8"
}

checkstyleMain {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in plugins.withId('checkstyle') {} ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no. checkstyle is always enabled so there's no need to include it in a block. The other things I moved to plugins.withId() must be moved into a conditional section to allow applying the plugins optional.

source = fileTree(dir: "src/main", include: "**/*.java")
}

checkstyleTest {
source = fileTree(dir: "src/test", include: "**/*.java")
checkstyleTest {
source = fileTree(dir: "src/test", include: "**/*.java")
}

// At a test failure, log the stack trace to the console so that we don't
// have to open the HTML in a browser.
test {
testLogging {
exceptionFormat = 'full'
showExceptions true
showCauses true
showStackTraces true
}
maxHeapSize = '1500m'
}

if (rootProject.properties.get('errorProne', true)) {
dependencies {
errorprone 'com.google.errorprone:error_prone_core:2.3.3'
errorproneJavac 'com.google.errorprone:javac:9+181-r4173-1'

annotationProcessor 'com.google.guava:guava-beta-checker:1.0'
}
} else {
// Disable Error Prone
allprojects {
afterEvaluate { project ->
project.tasks.withType(JavaCompile) {
options.errorprone.enabled = false
}
}
}
}

compileTestJava {
// LinkedList doesn't hurt much in tests and has lots of usages
options.errorprone.check("JdkObsolete", CheckSeverity.OFF)
}
}

plugins.withId("me.champeau.gradle.jmh") {
Expand All @@ -300,27 +317,10 @@ subprojects {
}

plugins.withId("maven-publish") {
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

publishing {
publications {
// do not use mavenJava, as java plugin will modify it via "magic"
maven(MavenPublication) {
if (project.name != 'grpc-netty-shaded') {
from components.java
}

artifact javadocJar
artifact sourcesJar

pom {
name = project.group + ":" + project.name
url = 'https://github.com/grpc/grpc-java'
Expand Down Expand Up @@ -400,18 +400,31 @@ subprojects {
required false
sign publishing.publications.maven
}
}

// At a test failure, log the stack trace to the console so that we don't
// have to open the HTML in a browser.
test {
testLogging {
exceptionFormat = 'full'
showExceptions true
showCauses true
showStackTraces true
plugins.withId("java") {
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}

publishing {
publications {
maven {
if (project.name != 'grpc-netty-shaded') {
from components.java
}

artifact javadocJar
artifact sourcesJar
}
}
}
}
maxHeapSize = '1500m'
}

// Run with: ./gradlew japicmp --continue
Expand Down
1 change: 1 addition & 0 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "cpp"
id "java"
id "maven-publish"

id "com.google.protobuf"
Expand Down
1 change: 1 addition & 0 deletions context/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "me.champeau.gradle.japicmp"
Expand Down
4 changes: 4 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "me.champeau.gradle.japicmp"
Expand All @@ -7,6 +8,9 @@ plugins {

description = 'gRPC: Core'

evaluationDependsOn(project(':grpc-context').path)
evaluationDependsOn(project(':grpc-api').path)

dependencies {
compile project(':grpc-api'),
libraries.gson,
Expand Down
3 changes: 3 additions & 0 deletions grpclb/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "com.google.protobuf"
Expand All @@ -7,6 +8,8 @@ plugins {

description = "gRPC: GRPCLB LoadBalancer plugin"

evaluationDependsOn(project(':grpc-core').path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had trouble with project(':grpc-core').sourceSets.test.output throwing, because the sourceSets weren't loaded yet because the java plugin wasn't loaded yet. Or some such. It was unfortunate, but the hack wasn't needed very many places and it wasn't at risk of forming a circular dependency.


dependencies {
compile project(':grpc-core'),
project(':grpc-protobuf'),
Expand Down
1 change: 1 addition & 0 deletions interop-testing/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "application"
id "java"
id "maven-publish"

id "com.google.protobuf"
Expand Down
1 change: 1 addition & 0 deletions netty/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "me.champeau.gradle.japicmp"
Expand Down
1 change: 1 addition & 0 deletions netty/shaded/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "com.github.johnrengelman.shadow"
Expand Down
1 change: 1 addition & 0 deletions okhttp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "me.champeau.gradle.japicmp"
Expand Down
1 change: 1 addition & 0 deletions protobuf-lite/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "com.google.protobuf"
Expand Down
1 change: 1 addition & 0 deletions protobuf/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "com.google.protobuf"
Expand Down
1 change: 1 addition & 0 deletions services/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "com.google.protobuf"
Expand Down
1 change: 1 addition & 0 deletions stub/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "me.champeau.gradle.japicmp"
Expand Down
1 change: 1 addition & 0 deletions testing-proto/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "com.google.protobuf"
Expand Down
1 change: 1 addition & 0 deletions testing/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "me.champeau.gradle.japicmp"
Expand Down
1 change: 1 addition & 0 deletions xds/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
id "java"
id "maven-publish"

id "com.github.johnrengelman.shadow"
Expand Down