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

Gradle file example from Getting Started Guide does not work #478

Closed
xetra11 opened this issue Jan 15, 2021 · 13 comments · Fixed by #479
Closed

Gradle file example from Getting Started Guide does not work #478

xetra11 opened this issue Jan 15, 2021 · 13 comments · Fixed by #479
Assignees
Labels
documentation Everything related to the documentation question A question about this library or its usage
Milestone

Comments

@xetra11
Copy link

xetra11 commented Jan 15, 2021

The context

The guide gives an example of a gradle build file here: https://yidongnan.github.io/grpc-spring-boot-starter/en/server/getting-started.html

The question

However the resolution of that file files for the first dependency tasks

Stacktraces and logs

FAILURE: Build completed with 2 failures.

1: Task failed with an exception.
-----------
* Where:
Build file '/home/xetra11/Development/projects/user-service/grpc-lib/build.gradle' line: 4

* What went wrong:
A problem occurred evaluating project ':grpc-lib'.
> Could not find method implementation() for arguments [io.grpc:grpc-protobuf:1.35.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

2: Task failed with an exception.
-----------
* What went wrong:
A problem occurred configuring project ':grpc-lib'.
> The com.google.protobuf plugin could not be applied during project evaluation. The Java plugin or one of the Android plugins must be applied to the project first.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
==============================================================================

* Get more help at https://help.gradle.org

BUILD FAILED in 94ms

The application's environment

The build file:

apply plugin: 'com.google.protobuf'

dependencies {
    compile "io.grpc:grpc-protobuf:1.35.0"
    compile "io.grpc:grpc-stub:1.35.0"
}

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'
    }
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.14.0"
    }
    generatedFilesBaseDir = "$projectDir/src/generated"
    clean {
        delete generatedFilesBaseDir
    }
    plugins {
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java"
        }
    }
    generateProtoTasks {
        all()*.plugins {
            grpc {}
        }
    }
}

buildscript {
    dependencies {
        classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.14"
    }
}
@xetra11 xetra11 added the question A question about this library or its usage label Jan 15, 2021
@ST-DDT
Copy link
Collaborator

ST-DDT commented Jan 15, 2021

Which version of gradle are you using?

@ST-DDT ST-DDT added the feedback required Information are missing or feedback for suggestions is requested label Jan 15, 2021
@xetra11
Copy link
Author

xetra11 commented Jan 15, 2021

I use v6.7.1
If you ask because of the compile -> implementation thing (deprecation) then I can assure you that I tried the same with implementation and it resulted in the same error.

* Where:
Build file '/home/xetra11/Development/projects/user-service/grpc-lib/build.gradle' line: 13

* What went wrong:
A problem occurred evaluating project ':grpc-lib'.
> Could not find method implementation() for arguments [io.grpc:grpc-protobuf:1.35.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

@ST-DDT ST-DDT removed the feedback required Information are missing or feedback for suggestions is requested label Jan 15, 2021
@ST-DDT
Copy link
Collaborator

ST-DDT commented Jan 15, 2021

Thanks for your response. I will check it later when I have some more time.

@ST-DDT ST-DDT added the documentation Everything related to the documentation label Jan 15, 2021
@ST-DDT ST-DDT self-assigned this Jan 15, 2021
@ST-DDT
Copy link
Collaborator

ST-DDT commented Jan 16, 2021

The compile is missing because you don't have the java/java-library plugin enabled.

plugins {
    id 'java'
}

I managed to run it using this build.gradle:

buildscript {
	dependencies {
		classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'
	}
}

plugins {
	id 'java-library'
	id 'com.google.protobuf' version '0.8.14'
}

repositories {
	mavenCentral()
}

dependencies {
	compile "io.grpc:grpc-protobuf:1.35.0"
	compile "io.grpc:grpc-stub:1.35.0"
}

protobuf {
	protoc {
		artifact = "com.google.protobuf:protoc:3.14.0"
	}
	generatedFilesBaseDir = "$projectDir/src/generated"
	clean {
		delete generatedFilesBaseDir
	}
	plugins {
		grpc {
			artifact = "io.grpc:protoc-gen-grpc-java:1.35.0"
		}
	}
	generateProtoTasks {
		all()*.plugins {
			grpc {}
		}
	}
}

I will adjust the docs to better reflect that.

@ST-DDT
Copy link
Collaborator

ST-DDT commented Jan 16, 2021

Can you please try/review the new configuration as shown in #479?

@xetra11
Copy link
Author

xetra11 commented Jan 16, 2021

@ST-DDT
Thanks! Looks promising. Just one last thing is happening

3:46:07 PM: Executing task ':grpc-lib:build'...

> Task :grpc-lib:extractIncludeProto
> Task :grpc-lib:extractProto
> Task :grpc-lib:generateProto

> Task :grpc-lib:compileJava FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings
4 actionable tasks: 4 executed
/home/xetra11/Development/projects/user-service/grpc-lib/src/generated/main/grpc/net/devh/boot/grpc/examples/lib/SimpleGrpc.java:10: error: cannot find symbol
@javax.annotation.Generated(
                 ^
  symbol:   class Generated
  location: package javax.annotation
1 error

FAILURE: Build failed with an exception.

@ST-DDT
Copy link
Collaborator

ST-DDT commented Jan 16, 2021

See referenced PR. The jackarta annotations api dependency is missing in J9+.

@xetra11
Copy link
Author

xetra11 commented Jan 16, 2021

@ST-DDT
Sorry for my incompetence but I can not see how this will solve the problem? You said the dependency is missing in Java 9 (and above). So what is the solution here? Downgrade to Java 8?

@ST-DDT
Copy link
Collaborator

ST-DDT commented Jan 16, 2021

You said the dependency is missing in Java 9 (and above). So what is the solution here? Downgrade to Java 8?

No you have to manually add it (You only need it at compile time).

https://github.com/yidongnan/grpc-spring-boot-starter/pull/479/files#diff-1d0b30595b8e001bbb8c5d3b4955ddd6926adde19ee2d071add30b504b624781R127

implementation 'jakarta.annotation:jakarta.annotation-api:2.0.0' // Java 9+ compatibility

I wished grpc would add it directly to their dependencies.

EDIT:

compileOnly 'jakarta.annotation:jakarta.annotation-api:1.3.5' // Java 9+ compatibility - Do NOT update to 2.0.0

@xetra11
Copy link
Author

xetra11 commented Jan 16, 2021

@ST-DDT
I did that. However it still does not work.
To have a full view of my problem here are both build files and the settings.gradle

Here is the root project build file:

// build.gradle.kts (Kotlin)

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
	id("org.springframework.boot") version "2.4.1"
	id("io.spring.dependency-management") version "1.0.10.RELEASE"
	kotlin("jvm") version "1.4.21"
	kotlin("plugin.spring") version "1.4.21"
	kotlin("plugin.jpa") version "1.4.21"
}

group = "com.myapp"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_15

repositories {
	mavenCentral()
}

dependencies {
	//implementation("org.springframework.boot:spring-boot-starter-data-jpa")
	implementation("org.springframework.boot:spring-boot-starter-web")
	implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
	implementation("org.jetbrains.kotlin:kotlin-reflect")
	implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
	implementation("jakarta.annotation:jakarta.annotation-api:2.0.0")
	testImplementation("org.springframework.boot:spring-boot-starter-test")
}

tasks.withType<KotlinCompile> {
	kotlinOptions {
		freeCompilerArgs = listOf("-Xjsr305=strict")
		jvmTarget = "15"
	}
}

tasks.withType<Test> {
	useJUnitPlatform()
}

Here is the grpc-lib module build file

// build.gradle (Gradle)
buildscript {
    dependencies {
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'
    }
}

plugins {
    id 'java'
    id 'java-library'
    id 'com.google.protobuf' version '0.8.14'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation "io.grpc:grpc-protobuf:1.35.0"
    implementation "io.grpc:grpc-stub:1.35.0"
    compile "jakarta.annotation:jakarta.annotation-api:2.0.0"
}

protobuf {
    protoc {
        artifact = "com.google.protobuf:protoc:3.14.0"
    }
    generatedFilesBaseDir = "$projectDir/src/generated"
    clean {
        delete generatedFilesBaseDir
    }
    plugins {
        grpc {
            artifact = "io.grpc:protoc-gen-grpc-java:1.35.0"
        }
    }
    generateProtoTasks {
        all()*.plugins {
            grpc {}
        }
    }
}

And finally the settings file

// settings.gradle.kts (Kotlin)

rootProject.name = "user-service"
include(":grpc-lib")

@ST-DDT
Copy link
Collaborator

ST-DDT commented Jan 16, 2021

Sorry for stating the wrong version. You have to use jakarta.annotation-api v1.3.5.
v2.0.0 changed the class names. For some strange reason, it did work in my previous tests though (maybe it was cached in the gradle daemon or maybe I just used J8...)

@xetra11
Copy link
Author

xetra11 commented Jan 16, 2021

@ST-DDT
Thank god now it works. You saved my day <3

@xetra11 xetra11 closed this as completed Jan 16, 2021
@ST-DDT
Copy link
Collaborator

ST-DDT commented Jan 16, 2021

Glad I could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Everything related to the documentation question A question about this library or its usage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants