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
12 changes: 3 additions & 9 deletions all/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
apply plugin: 'com.github.kt3k.coveralls'
plugins {
id "com.github.kt3k.coveralls"
}

description = "gRPC: All"

buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
Copy link
Member

Choose a reason for hiding this comment

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

To keep the old behavior, you might add this in settings.gradle

pluginManagement {
    repositories {
        maven { // The google mirror is less flaky than mavenCentral()
            url "https://maven-central.storage-download.googleapis.com/repos/central/data/"
        }
        gradlePluginPortal()
    }
}

Copy link
Member Author

Choose a reason for hiding this comment

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

We aren't using mavenCentral any more, so using the Google mirror isn't all that useful. But even more, it can't load the plugins from the google mirror, because the search will be based on the name com.github.kt3k.coveralls, not org.kt3k.gradle.plugin:coveralls-gradle-plugin. While there are ways to make that work, they require some effort and it doesn't seem all that helpful given most of the plugins are not available on the google mirror.

}
dependencies { classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1' }
}

def subprojects = [
project(':grpc-api'),
project(':grpc-auth'),
Expand Down
16 changes: 3 additions & 13 deletions alts/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
buildscript {
repositories { jcenter() }
dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4' }
plugins {
id "com.github.johnrengelman.shadow"
id "com.google.protobuf"
}

apply plugin: 'com.github.johnrengelman.shadow'

description = "gRPC: ALTS"

sourceCompatibility = 1.7
targetCompatibility = 1.7

buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
}
dependencies { classpath libraries.protobuf_plugin }
}

dependencies {
compile project(':grpc-auth'),
project(':grpc-core'),
Expand Down
12 changes: 4 additions & 8 deletions benchmarks/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
}
dependencies { classpath libraries.protobuf_plugin }
}
plugins {
id "application"

apply plugin: 'application'
id "com.google.protobuf"
}

description = "grpc Benchmarks"

Expand Down
20 changes: 6 additions & 14 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
buildscript {
repositories {
mavenLocal()
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'com.google.gradle:osdetector-gradle-plugin:1.4.0'
classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.5.0'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:0.8.1'
classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.5"
classpath 'me.champeau.gradle:japicmp-gradle-plugin:0.2.5'
}
plugins {
id "com.google.osdetector" apply false
id "me.champeau.gradle.japicmp" apply false
id "me.champeau.gradle.jmh" apply false
id "net.ltgt.errorprone" apply false
id "ru.vyarus.animalsniffer" apply false
}

import net.ltgt.gradle.errorprone.CheckSeverity
Expand Down Expand Up @@ -115,7 +109,6 @@ subprojects {

configureProtoCompilation = {
String generatedSourcePath = "${projectDir}/src/generated"
project.apply plugin: 'com.google.protobuf'
project.protobuf {
protoc {
if (project.hasProperty('protoc')) {
Expand Down Expand Up @@ -205,7 +198,6 @@ subprojects {
protobuf: "com.google.protobuf:protobuf-java:${protobufVersion}",
protobuf_lite: "com.google.protobuf:protobuf-lite:3.0.1",
protoc_lite: "com.google.protobuf:protoc-gen-javalite:3.0.0",
protobuf_plugin: 'com.google.protobuf:protobuf-gradle-plugin:0.8.8',
protobuf_util: "com.google.protobuf:protobuf-java-util:${protobufVersion}",
lang: "org.apache.commons:commons-lang3:3.5",

Expand Down
16 changes: 5 additions & 11 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
apply plugin: "cpp"
apply plugin: "com.google.protobuf"
plugins {
id "cpp"

description = 'The protoc plugin for gRPC Java'

buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
mavenLocal()
}
dependencies { classpath libraries.protobuf_plugin }
id "com.google.protobuf"
}

description = 'The protoc plugin for gRPC Java'

def artifactStagingPath = "$buildDir/artifacts" as File
// Adds space-delimited arguments from the environment variable env to the
// argList.
Expand Down
10 changes: 7 additions & 3 deletions gae-interop-testing/gae-jdk8/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
description = 'gRPC: gae interop testing (jdk8)'

buildscript {
// Configuration for building
Expand All @@ -26,6 +25,13 @@ buildscript {
}
}

plugins {
id "java"
Copy link
Member

Choose a reason for hiding this comment

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

It seems all projects explicitly apply java plugin, why not apply it in rootDir/build.gradle?
It is for migration to java-library?

Copy link
Member Author

Choose a reason for hiding this comment

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

1 ) Android should not include Java, which is a follow-up PR and 2) make it easier to swap to java-library, since java-library will only apply to a subset of projects. "java" plugin has historically been the main problem, so it was the most important one to move into individual projects. Things like maven-publish were more icing on the cake.

id "war"
}

description = 'gRPC: gae interop testing (jdk8)'

repositories {
// repositories for Jar's you access in your code
mavenLocal()
Expand All @@ -34,8 +40,6 @@ repositories {
jcenter()
}

apply plugin: 'java' // standard Java tasks
apply plugin: 'war' // standard Web Archive plugin
apply plugin: 'com.google.cloud.tools.appengine' // App Engine tasks
Copy link
Member

Choose a reason for hiding this comment

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

Any reason 'com.google.cloud.tools.appengine' is not moved to plugins {}?

Copy link
Member Author

Choose a reason for hiding this comment

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

It isn't on the plugins.gradle.org so the new plugin syntax doesn't work. I later figured out a way to solve that for Android, and I could apply it here. But I also didn't care too much about this file since it is already out-of-the-way and not causing trouble. Also also, I would still need the okhttp dependency in the buildscript {} section since it is used by the testing code below, so I can't clean up this file completely anyway.


dependencies {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 4 additions & 8 deletions grpclb/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
description = "gRPC: GRPCLB LoadBalancer plugin"

buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
}
dependencies { classpath libraries.protobuf_plugin }
plugins {
id "com.google.protobuf"
}

description = "gRPC: GRPCLB LoadBalancer plugin"

dependencies {
compile project(':grpc-core'),
project(':grpc-protobuf'),
Expand Down
15 changes: 5 additions & 10 deletions interop-testing/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
apply plugin: 'application'
plugins {
id "application"

id "com.google.protobuf"
}

description = "gRPC: Integration Testing"
startScripts.enabled = false

// Add dependency on the protobuf plugin
buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
}
dependencies { classpath libraries.protobuf_plugin }
}

dependencies {
compile project(':grpc-alts'),
project(':grpc-auth'),
Expand Down
7 changes: 2 additions & 5 deletions netty/shaded/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
buildscript {
repositories { jcenter() }
dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4' }
plugins {
id "com.github.johnrengelman.shadow"
}

apply plugin: 'com.github.johnrengelman.shadow'

description = "gRPC: Netty Shaded"

sourceSets { testShadow {} }
Expand Down
11 changes: 2 additions & 9 deletions protobuf-lite/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
mavenLocal()
}
dependencies { classpath libraries.protobuf_plugin }
plugins {
id "com.google.protobuf"
}

apply plugin: 'com.google.protobuf'

description = 'gRPC: Protobuf Lite'

dependencies {
Expand Down
12 changes: 4 additions & 8 deletions protobuf/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
description = 'gRPC: Protobuf'

buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
}
dependencies { classpath libraries.protobuf_plugin }
plugins {
id "com.google.protobuf"
}

description = 'gRPC: Protobuf'

dependencies {
compile project(':grpc-api'),
libraries.protobuf
Expand Down
9 changes: 2 additions & 7 deletions services/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// Add dependency on the protobuf plugin
buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
}
dependencies { classpath libraries.protobuf_plugin }
plugins {
id "com.google.protobuf"
}

description = "gRPC: Services"
Expand Down
13 changes: 13 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
pluginManagement {
plugins {
Copy link
Member

Choose a reason for hiding this comment

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

This method (PluginManagementSpec.plugins) is incubating, why not just specify versions in build.gradle?

Copy link
Member Author

Choose a reason for hiding this comment

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

You can't use variable names in plugins {} blocks; there can't be any logic. So that would require having a plugins section in the root build.gradle with apply false for each. But I think that is still functionally different from this, in the way transitive dependencies will be loaded for each project. A bit uncertain. In any case, this seemed much nicer and since it is only in one location didn't seem too much worry if they change the API some in the future.

Also, I plan to move all of our library versions into this file, as Gradle allows specifying dependencies without a version and having this file choose the version to use. That would be much nicer than figuring out which variable to use. But this also relates to some pinning support I want to use, lock files, and more which I've not had time to integrate and verify that they don't regress our Maven Central pom.xml output.

id "com.github.johnrengelman.shadow" version "2.0.4"
id "com.github.kt3k.coveralls" version "2.0.1"
id "com.google.osdetector" version "1.4.0"
id "com.google.protobuf" version "0.8.8"
id "me.champeau.gradle.japicmp" version "0.2.5"
id "me.champeau.gradle.jmh" version "0.4.5"
id "net.ltgt.errorprone" version "0.8.1"
id "ru.vyarus.animalsniffer" version "1.5.0"
}
}

rootProject.name = "grpc"
include ":grpc-api"
include ":grpc-core"
Expand Down
13 changes: 4 additions & 9 deletions testing-proto/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
description = "gRPC: Testing Protos"

// Add dependency on the protobuf plugin
buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
}
dependencies { classpath libraries.protobuf_plugin }
plugins {
id "com.google.protobuf"
}

description = "gRPC: Testing Protos"

dependencies {
compile project(':grpc-protobuf'),
project(':grpc-stub')
Expand Down
17 changes: 3 additions & 14 deletions xds/build.gradle
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
// Add dependency on the protobuf plugin
buildscript {
repositories {
maven { // The google mirror is less flaky than mavenCentral()
url "https://maven-central.storage-download.googleapis.com/repos/central/data/" }
gradlePluginPortal()
}
dependencies {
classpath libraries.protobuf_plugin
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
}
plugins {
id "com.github.johnrengelman.shadow"
id "com.google.protobuf"
}

apply plugin: 'com.github.johnrengelman.shadow'

description = "gRPC: XDS plugin"

[compileJava].each() {
Expand Down Expand Up @@ -42,7 +32,6 @@ dependencies {
signature "org.codehaus.mojo.signature:java17:1.0@signature"
}

apply plugin: 'com.google.protobuf'
sourceSets {
main {
proto {
Expand Down