I am trying to create implement client-server communication with the help of grpc
proto file -
syntax="proto3";
package com.project.grpc.roleservice;
message UserRequest {
string userName=1;
}
message RoleReply {
string userRole=1;
}
service UserRoleFromServer{
rpc getRoleUser(stream UserRequest) returns (stream RoleReply);
}
Gradle build -
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.5")
}
}
plugins {
id 'java'
}
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.google.protobuf'
group 'com.project.grpc.roleservice'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:3.5.1-1"
}
plugins {
grpc {
artifact = 'io.grpc:protoc-gen-grpc-java:1.16.1'
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-web')
compile( 'io.grpc:grpc-netty-shaded:1.16.1')
compile('io.grpc:grpc-protobuf:1.16.1')
compile('io.grpc:grpc-stub:1.16.1')
compile 'io.github.lognet:grpc-spring-boot-starter:3.0.0'
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile (group: 'junit', name: 'junit', version: '4.12')
}
After building the project all the files are generated in a build folder and a UserRoleFromServerGrpc is generated which I want to extend and implement in my server-service file
But The UserRoleFromServerGrpc has a lot of errors it asks for following dependencies
Streamobserver needs io.grpc:grpc-stub:1.16.1 ,grpc-core
Add io.grpc:grpc-stub:1.16.1 to classpath
but I have already defined these dependencies in gradle build
How to resolve this issue
Screenshot of IDE
Related
I am trying to combine a Spring Boot backend api and a React frontend app into one single jar.
I was able to build a jar file containing both by following this article (https://medium.com/xebia-engineering/a-minimalistic-guide-to-building-and-deploying-monolithic-spring-boot-react-applications-39440035b27) but the frontend jar ends up in BOOT-INF/lib/frontend.jar instead of META-INF/resources. How can I create a jar file with the webjar in the right directory so it can render a React page?
frontend/build.gradle
plugins {
id "com.moowork.node" version "1.3.1"
}
apply plugin: "java"
apply plugin: "com.moowork.node"
node {
version = "12.9.1"
download = true
}
task bundle(type: NpmTask, dependsOn: npmInstall) {
args = ["run", "build"]
}
task uiTest(type: NpmTask) {
environment = ["CI": "true"]
args = ["run", "test"]
}
task run(type: NpmTask) {
args = ["start"]
}
check.dependsOn(test)
jar.dependsOn(bundle)
task webjar(type: Jar) {
from(fileTree("build")) {
into "META-INF/resources"
}
}
check.dependsOn(test)
jar.dependsOn(bundle)
jar.finalizedBy("webjar")
backend/build.gradle
plugins {
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'java'
}
apply plugin: 'io.spring.dependency-management'
apply plugin: 'maven'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/libs-milestone'
}
}
jar {
manifest {
attributes "Main-Class": "com.example.kasahararestapi.StockCheckAppApplication"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Test.class" // whatever Ant pattern matches your test class files
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-security'
runtimeOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'mysql:mysql-connector-java'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.social:spring-social-github:1.0.0.M4'
implementation 'commons-io:commons-io:2.6'
implementation 'org.apache.commons:commons-lang3:3.0'
implementation 'io.jsonwebtoken:jjwt:0.9.0'
implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.807')
implementation 'com.amazonaws:aws-java-sdk-s3'
implementation 'org.springframework.boot:spring-boot-starter-mail:1.2.0.RELEASE'
implementation 'org.modelmapper:modelmapper:2.3.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
implementation project(path: ':frontend', configuration: 'default')
}
setting.gradle
pluginManagement {
repositories {
gradlePluginPortal()
}
}
rootProject.name = 'stock_check_app'
include 'backend'
include 'frontend'
I am creating javafx app with spring boot in background. To do this I used this library: springboot-javafx-support Every time when I start it I get exception "No auto configuration found in META-INF/spring.factories". I have no idea what I am doing wrong. I guess it must be something wrong in my gradle build script.
Below you can find gradle.build file
buildscript {
ext {
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
//apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'pl.opfol.subiekt'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.9
sourceSets {
main.java.srcDirs += 'build/generated/source/apt/main'
}
jar {
enabled = true
}
bootJar {
mainClassName = 'pl.opfol.subiekt.util.MainApp'
}
repositories {
mavenCentral()
maven {
url "https://artifact.aspose.com/repo"
}
maven {
url "https://dl.bintray.com/jerady/maven"
}
}
dependencies {
compile 'org.projectlombok:lombok:1.16.20'
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-validation')
compile('org.springframework.boot:spring-boot-starter-logging')
compile('com.h2database:h2:1.4.197')
compile('javax.mail:javax.mail-api:1.6.1')
compile('com.sun.mail:javax.mail:1.6.1')
compile('commons-io:commons-io:2.6')
compile('commons-codec:commons-codec:1.11')
compile('org.apache.commons:commons-collections4:4.1')
compile('org.apache.commons:commons-lang3:3.7')
compile('commons-configuration:commons-configuration:1.10')
compile('com.aspose:aspose-words:17.3.0:jdk16')
compile('com.microsoft.sqlserver:mssql-jdbc:6.4.0.jre9')
compile('javax.annotation:javax.annotation-api:1.3.2')
compile('org.controlsfx:controlsfx:9.0.0')
compile('com.itextpdf:itext7-core:7.1.1')
compile('javax.xml.bind:jaxb-api:2.3.0')
compile('com.jfoenix:jfoenix:9.0.0')
compile('de.roskenet:springboot-javafx-support:2.1.6')
compile('de.jensd:fontawesomefx-controls:9.1.2')
compile('de.jensd:fontawesomefx-commons:9.1.2')
compile('de.jensd:fontawesomefx-weathericons:2.0.10-9.1.2')
compile('de.jensd:fontawesomefx-materialicons:2.2.0-9.1.2')
compile('de.jensd:fontawesomefx-materialdesignfont:2.0.26-9.1.2')
compile('de.jensd:fontawesomefx-octicons:4.3.0-9.1.2')
compile('de.jensd:fontawesomefx-fontawesome:4.7.0-9.1.2')
compile('de.jensd:fontawesomefx-materialstackicons:2.1-5-9.1.2')
compile('de.jensd:fontawesomefx-icons525:4.2.0-9.1.2')
compile('de.jensd:fontawesomefx-emojione:3.1.1-9.1.2')
compileOnly ('org.hibernate:hibernate-jpamodelgen:5.2.16.Final')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
I had same problem, make sure you run it on JRE 1.8.
I am coming from Maven workd and new to Gradle.I have multi-module Gradle product with following modules:
"cdna-common"
'cdna-data-access'
"cdna-api-dto"
"cdna-api-module"
"cdna-request-executor-module"
my root settings.glade looks like this:
rootProject.name = 'cdna-one-platform'
include "cdna-common"
include 'cdna-data-access'
//include "cdna-api-dto" //commented temporary
include "cdna-api-module"
//include "cdna-request-executor-module" //commented temporary
gradle file for module 'cdna-data-access' is :
buildscript {
ext {
springBootVersion = '2.0.0.M6'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
ext['hibernate.version'] = '5.2.11.Final'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.company.cdna'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
jar {
baseName = 'cdna-one-data-access'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
a
dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile('mysql:mysql-connector-java')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.hibernate:hibernate-search-orm')
compile group: 'org.hibernate', name: 'hibernate-search-orm' , version: '5.8.2.Final'
compile group: 'org.apache.lucene', name: 'lucene-analyzers-kuromoji' , version: '5.5.5'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('com.h2database:h2')
}
Module 'cdna-common' depends on 'cdna-one-data-access' and gradle file looks like :
apply plugin: 'java'
apply plugin: 'eclipse'
group = 'com.company.cdna'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
jar {
baseName = 'cdna-one-commons'
}
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
}
dependencies {
compile project(':cdna-data-access')
}
When I compile the module 'cdnHowever,cess' using 'gradlew cdna-data-access:build' , it compiles without any error.
However , when I try to compile the module 'cdna-common' using 'gradlew cdna-common:build' , it gives following error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all files for configuration ':cdna-common:compileClasspath'.
> Could not find org.springframework.boot:spring-boot-starter:.
Searched in the following locations:
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter//spring-boot-starter-.pom
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter//spring-boot-starter-.jar
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-starter//spring-boot-starter-.pom
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-starter//spring-boot-starter-.jar
https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter//spring-boot-starter-.pom
https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter//spring-boot-starter-.jar
Required by:
project :cdna-common > project :cdna-data-access
> Could not find mysql:mysql-connector-java:.
Searched in the following locations:
https://repo1.maven.org/maven2/mysql/mysql-connector-java//mysql-connector-java-.pom
https://repo1.maven.org/maven2/mysql/mysql-connector-java//mysql-connector-java-.jar
https://repo.spring.io/snapshot/mysql/mysql-connector-java//mysql-connector-java-.pom
https://repo.spring.io/snapshot/mysql/mysql-connector-java//mysql-connector-java-.jar
https://repo.spring.io/milestone/mysql/mysql-connector-java//mysql-connector-java-.pom
https://repo.spring.io/milestone/mysql/mysql-connector-java//mysql-connector-java-.jar
Required by:
project :cdna-common > project :cdna-data-access
> Could not find org.springframework.boot:spring-boot-starter-data-jpa:.
Searched in the following locations:
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.pom
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.jar
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.pom
https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.jar
https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.pom
https://repo.spring.io/milestone/org/springframework/boot/spring-boot-starter-data-jpa//spring-boot-starter-data-jpa-.jar
Required by:
project :cdna-common > project :cdna-data-access
Any tips of what I am doing wrong?
As the title says. I'm using IntelliJ IDEA 2017.1.4
My gradle file is following:
group 'org.ks'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:1.4.7.RELEASE"
}
}
apply plugin: "org.springframework.boot"
task wrapper(type: Wrapper) {
gradleVersion = '2.4'
}
apply plugin: 'java'
apply plugin: "io.spring.dependency-management"
sourceCompatibility = 1.8
targetCompatibility = 1.8
But the attempt to use #Autowired annotation causes compilation error
package app;
import org.springframework.beans.factory.annotation.Autowired;
public class AutowiredCls {
#Autowired
private int app_name;
}
Compiler marks import and #Autowired as errors (red underline)
application.yml:
app.name = autowired_sample
What do I do wrong?
Please add below dependencies, you can refer to this for more details
dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
}
It doesn't look like your project has any dependencies at all. (I can see that your buildscript has dependencies... but these will not apply to the project sources thamselves.)
Here is a build.gradle file from a project I once generated using https://start.spring.io:
buildscript {
ext {
springBootVersion = '1.3.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'spring-boot'
apply plugin: 'war'
war {
baseName = 'soffit-samples'
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-cache')
compile('org.springframework.boot:spring-boot-starter-web')
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
The project itself (my sources) contains 2 dependencies defined for the compile scope:
org.springframework.boot:spring-boot-starter-cache
org.springframework.boot:spring-boot-starter-web
Both of these are Spring dependencies. I imagine that one (or both) of these give my sources access to the #Autowired annotation... either directly or transitively (probably transitively).
FYI - I 've found the solution. It's best to visit start.spring.io to generate gradle.
build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
jar {
baseName = 'gs-spring-boot'
version = '0.1.0'
}
repositories {
mavenCentral()
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile('org.springframework.boot:spring-boot-autoconfigure')
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile("junit:junit")
}
gradle.properties:
springVersion=1.5.8.RELEASE
This is my build.gradle file
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.moowork.gradle:gradle-grunt-plugin:0.13'
classpath "gradle.plugin.com.github.scobal.eslint:gradle-eslint-plugin:1.0.1"
}
}
plugins{
id "com.moowork.grunt" version "0.13"
id "com.moowork.node" version "0.13"
}
// apply all plug-ins
apply plugin: 'com.moowork.grunt'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: "com.github.scobal.eslint"
sourceCompatibility = 1.8
//version = '24.1.1.0'
war.doFirst{
deleteFiles()
grunt_build()
grunt_compile()
}
task deleteFiles(type: Delete){
delete fileTree("${System.properties['TOMCAT_HOME']}/webapps"){
include '**/*.war'
}
}
task deployToTomcat(type: Copy) {
from war.archivePath
into "${System.properties['TOMCAT_HOME']}/webapps"
}
deployToTomcat.doFirst{
war()
}
clean.doFirst{
deleteFiles
}
eslint {
inputs = ["./src/**/*.js"]
}
// exclude the files we don't want to deliver
// TODO - is there an easier way to exclude all directories under js??? We don't want any of them.
war {
exclude('src/js/main.js')
exclude('src/js/actions')
exclude('src/js/api')
exclude('src/js/components')
exclude('src/js/constants')
exclude('src/js/dispatcher')
exclude('src/js/stores')
}
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart' //,
//'Implementation-Version': version
}
}
repositories {
mavenCentral()
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
compile("org.springframework:spring-webmvc:4.0.3.RELEASE")
compile("com.fasterxml.jackson.core:jackson-core:2.7.4")
compile("com.fasterxml.jackson.core:jackson-annotations:2.7.4")
compile("com.fasterxml.jackson.core:jackson-databind:2.7.4")
compile("org.darkphoenixs:log4j:1.2.17")
compile files('libs/opla230.jar')
testCompile group: 'junit', name: 'junit', version: '4.+'
}
test {
systemProperties 'property': 'value'
}
uploadArchives {
repositories {
flatDir {
dirs 'repos'
}
}
}
The problem that's happening is that the deployToTomcat is running first and deploying an old war on the tomcat. After that the war task of the war plugin runs and generates a new war which never gets deployed. Can someone help me with the enforcing of the order of these actions.
You need to add "dependsOn war" in your deployToTomcat task.