gRPC generated java files are getting duplicated or regenerated : class ClassNameGrpc is public and should be declared in a file named ClassNameGrpc - build.gradle

I have created a gradle java project with 2 modules :
grpc client module
grpc server module
When i build them, for some reason the grpc and protobuf files are getting generated more than once. The 2nd file is getting generated with "2" suffixed and as such throwing error as shown in screen shot below.
The gradle file is as below and this is same in client and server.
apply plugin: 'java'
apply plugin: 'com.google.protobuf'
repositories {
mavenCentral()
}
def grpcVersion = '1.24.1'
dependencies {
compile "io.grpc:grpc-netty:${grpcVersion}"
compile "io.grpc:grpc-protobuf:${grpcVersion}"
compile "io.grpc:grpc-stub:${grpcVersion}"
compile 'com.google.protobuf:protobuf-java:3.9.2'
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.10'
}
}
protobuf {
protoc {
artifact = 'com.google.protobuf:protoc:3.9.2'
}
plugins {
grpc {
artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all()*.plugins {
grpc {}
}
}
}
sourceSets {
main {
java {
srcDirs 'build/generated/source/proto/main/grpc'
srcDirs 'build/generated/source/proto/main/java'
}
}
}
jar {
manifest {
attributes "Main-Class": "ecommerce.ecommerce.OrderMgtServer"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}
// Generate IntelliJ IDEA's .idea & .iml project files
apply plugin: 'idea'
// Provide convenience executables for trying out the examples.
apply plugin: 'application'
startScripts.enabled = false

Use only one sourceSets {main { java· added the java plugin and the protobuf plugin of your version at the build.gradle.
plugins {
    id 'java'
    id 'com.google.protobuf' version '0.8.10'
    id 'idea'
}
dependencies {
implementation "io.grpc:grpc-netty-shaded:$grpc_version"
implementation "io.grpc:grpc-protobuf:$grpc_version"
implementation "io.grpc:grpc-stub:$grpc_version"
implementation "io.grpc:grpc-services:$grpc_version" // reflection
}
sourceSets.main.java.srcDir new File(buildDir, 'generated/source')
idea {
    module {
        // Marks the already(!) added srcDir as "generated"
        generatedSourceDirs += file('build/generated/source')
    }
}
After editing the build.gradle execute a task -> clean and task -> generateProtobuff. I think with it you fix your errors. About the dependencies.compile I am not sure if it affects. But I am using dependencies.implementation.

Related

LibGDX html:superDev task giving me an error

So I've been trying to run the libGDX command "gradlew html:superDev" for my project but it always gives me and error part way through the process:
> Task :html:beforeRun FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':html:beforeRun'.
> Could not resolve all files for configuration ':html:grettyRunnerJetty94'.
> Could not find org.gretty:gretty-runner-jetty94:3.0.2.
Searched in the following locations:
- file:/C:/Users/Joachim/.m2/repository/org/gretty/gretty-runner-jetty94/3.0.2/gretty-runner-jetty94-3.0.2.pom
- https://repo.maven.apache.org/maven2/org/gretty/gretty-runner-jetty94/3.0.2/gretty-runner-jetty94-3.0.2.pom
- https://dl.google.com/dl/android/maven2/org/gretty/gretty-runner-jetty94/3.0.2/gretty-runner-jetty94-3.0.2.pom
- https://oss.sonatype.org/content/repositories/snapshots/org/gretty/gretty-runner-jetty94/3.0.2/gretty-runner-jetty94-3.0.2.pom
- https://oss.sonatype.org/content/repositories/releases/org/gretty/gretty-runner-jetty94/3.0.2/gretty-runner-jetty94-3.0.2.pom
Required by:
project :html
* 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
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
This is what the build.gradle file looks like (the one located in the project folder):
buildscript {
repositories {
gradlePluginPortal()
mavenLocal()
mavenCentral()
maven { url "https://plugins.gradle.org/m2/" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
google()
}
dependencies {
classpath 'org.wisepersist:gwt-gradle-plugin:1.0.13'
classpath 'org.gretty:gretty:3.0.3'
}
}
allprojects {
apply plugin: "eclipse"
version = '1.0'
ext {
appName = "ludum-dare-48"
gdxVersion = '1.9.14'
roboVMVersion = '2.3.12'
box2DLightsVersion = '1.5'
ashleyVersion = '1.7.3'
aiVersion = '1.8.2'
gdxControllersVersion = '2.1.0'
}
repositories {
gradlePluginPortal()
mavenLocal()
mavenCentral()
google()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java-library"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
}
}
project(":html") {
apply plugin: "java-library"
apply plugin: "gwt"
apply plugin: "war"
apply plugin: "org.gretty"
dependencies {
implementation project(":core")
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion"
api "com.badlogicgames.gdx:gdx:$gdxVersion:sources"
api "com.badlogicgames.gdx:gdx-backend-gwt:$gdxVersion:sources"
api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion:sources"
}
}
project(":core") {
apply plugin: "java-library"
dependencies {
api "com.badlogicgames.gdx:gdx:$gdxVersion"
api "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
}
}
Any help in fixing this problem would be very much appreciated. Thanks!
In the maven reposotories it seems that there is no such version 3.0.2 of the project you are looking for. Maybe it got deleted and replaced by version 3.0.3.
So a solution would be to check your build.gradle file (probably the one in the html project) and replace the string org.gretty:gretty-runner-jetty94:3.0.2 by either org.gretty:gretty-runner-jetty94:3.0.3 or org.gretty:gretty-runner-jetty94:2.3.0.
You should try version 3.0.3 first, since 2.3.0 might be lacking some features.
Ok so I went to my main gradle.build file and in the repositories {} block for both the buildscript {} block and the allprojects {} block I put gradlePluginPortal() and now the superDev command works fine.

LibGDX FlappyBird

I'm trying to work my way through a tutorial (https://www.youtube.com/watch?v=rzBVTPaUUDg) and I"m stuck at the beginning. I'm trying to learn this stuff. Having a blast but just stuck in the gate.
build gradle:
buildscript {
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
allprojects {
apply plugin: "eclipse"
apply plugin: "idea"
version = '1.0'
ext {
appName = 'FloppyDemo'
gdxVersion = '1.6.3'
roboVMVersion = '1.4.0'
box2DLightsVersion = '1.3'
ashleyVersion = '1.4.0'
aiVersion = '1.5.0'
}
repositories {
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":desktop") {
apply plugin: "java"
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
}
}
project(":android") {
apply plugin: "android"
configurations { natives }
dependencies {
compile project(":core")
compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
}
}
project(":core") {
apply plugin: "java"
dependencies {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
}
}
tasks.eclipse.doLast {
delete ".project"
}
The Error I get:
Error:Gradle: A problem occurred configuring root project 'FloppyDemo'.
Could not resolve all files for configuration ':classpath'.
Could not find com.android.tools.build:gradle:3.0.1.
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
https://repo1.maven.org/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
https://oss.sonatype.org/content/repositories/snapshots/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
https://oss.sonatype.org/content/repositories/snapshots/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
Required by:
project :
Migrate to Android Plugin for Gradle 3.0.1
Update Gradle version
Android plugin 3.0.1 requires Gradle version 4.1 or higher.
To update Gradle manually, Find gradle folder inside your project and edit the URL in gradle-wrapper.properties to the following:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Apply the plugin
Add google maven repo inside buildscript tag
buildscript {
repositories {
...
google() // <-- Add this
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
Before proceeding to update, you should check this thread and this

How to use com.google.appengine.labs.repackaged.org.json in Android Studio

I have working code which uses JSON with package shown below.
import com.google.appengine.labs.repackaged.org.json.JSONException;
import com.google.appengine.labs.repackaged.org.json.JSONObject;
Code runs in app engine, built under eclipse. And now I'm trying to migrate it to Android Studio. But I can't find out how to refer correct library with it, so I can't compile. My current build.gradle file is shown below.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.google.appengine:gradle-appengine-plugin:1.9.18'
}
}
repositories {
jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
war.dependsOn appengineEnhance
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
compile 'com.google.appengine:appengine-endpoints:1.9.18'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.18'
compile 'com.google.appengine.orm:datanucleus-appengine:2.1.2'
compile 'javax.servlet:servlet-api:2.5'
compile 'javax.jdo:jdo2-api:2.3-eb'
compile 'org.datanucleus:datanucleus-api-jdo:3.1.3'
}
appengine {
downloadSdk = true
appcfg {
oauth2 = true
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
enhancer {
version = "v2"
api="jdo"
enhanceOnBuild = true
}
}
There are other libraries I need to add but I want to fix this issue first.
I found a solution. Adding next line to build.gradle made successful compile.
compile 'com.google.appengine:appengine-api-labs:1.7.4'
Now I can go forward to run/debug server side code.

Error while building fat jar for deploying my jar to remote Cluster

I have set up a single node cluster and trying to deploy my sample topology to it .
I believe to deploy my topology to cluster I have to submit the jar with all dependencies to the Cluster .
For that I created a sample project and added a simple topology to it .
While generating the fat jar using gradle I am seeing this error
gradle fatjar gives below error
Could not expand ZIP '/Users/agarg/.gradle/caches/modules-2/files-
2.1/org.apache.storm/storm-
core/0.9.5/d2bf27db853347dcf66990b4514db20a7897303e/storm-core-0.9.5.jar'.
Could not copy zip entry /Users/agarg/.gradle/caches/modules-2/files-
2.1/org.apache.storm/storm-
core/0.9.5/d2bf27db853347dcf66990b4514db20a7897303e/storm-core-
0.9.5.jar!META-INF/license/LICENSE.base64.txt to '/Users/agarg/Documents/notificationRepo/sample/build/tmp/expandedArchives/storm-
core-0.9.5.jar_366us3312tpl54tci2fld83fij/META-INF/license/LICENSE.base64.txt'.
Here is my build.gradle file fo reference :
dependencies {
compile group: 'clj-stacktrace' , name: 'clj-stacktrace',version: cljStackTrace
compile group: 'org.apache.storm' , name: 'storm-core',version: stormVersion
}
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version,
'Main-Class': 'storm.topology.ExclamationTopology'
}
baseName = project.name + '-all'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
buildscript {
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/snapshot' }
maven { url 'http://repo.spring.io/milestone' }
maven { url "https://clojars.org/repo/" }
maven { url "http://repo.maven.apache.org/maven2" }
}
}
Can nyone help me what is going wrong here ???
Thanks In Advance
I am not familiar with gradle, however, you do not need to include "storm-core" or transitive dependencies in your fat jar. It is sufficient if your far jar contains Spout and Bolt classes (and maybe some 3rd party libraries you are using that are not part of Storm)

Gradle custom task only applied to certain subprojects?

I have created a custom herpderp Gradle task:
task herpderp(type: HerpDerpTask)
class HerpDerpTask extends DefaultTask {
#TaskAction
def herpderp() {
println "Herp derp!"
}
}
With this, I can add this task to other Gradle builds an use it inside build invocations for other projects:
gradle clean build herpderp
Now, I have the following multi-project setup:
myapp/
myapp-client/
build.gradle
src/** (omitted for brevity)
myapp-shared/
build.gradle
src/** (omitted for brevity)
myapp-server
build.gradle
src/** (omitted for brevity)
build.gradle
settings.gradle
Where myapp/build.gradle is:
subprojects {
apply plugin: 'groovy'
sourceCompatibility = '1.7'
targetCompatibility = '1.7'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile (
'org.codehaus.groovy:groovy-all:2.3.7'
)
}
}
And where myapp/settings.gradle is:
include ':myapp-shared'
include ':myapp-client'
include ':myapp-server'
I would like to be able to navigate to the parent myapp directory, and run gradler clean build herpderp and have the herpderp task only run on the myapp-client and myapp-shared projects (not the server project).
So it sounds like I need either another custom task or some type of closure/method inside myapp/build.gradle that:
Runs clean build; then
Drops (cd) into myapp-client and runs herpderp; and then
Drop into myapp-shared and runs herpderp.
What do I need to add to any of my files in order to get herpderp invoked from the parent build command, but only executed in the client and shared subprojects?
The following piece of code can do the trick (should be placed in myapp/build.gradle):
allprojects.findAll { it.name in ['myapp-client', 'myapp-shared'] }. each { p ->
configure(p) {
task herpderp(type: HerpDerpTask)
}
}
class HerpDerpTask extends DefaultTask {
#TaskAction
def herpderp() {
println "Herp derp from ${project.name}!"
}
}
As indicated in the Gradle documentation, you can filter subprojects and configure them this way:
configure(subprojects.findAll { it.name.endsWith("server") }) {
apply plugin: 'com.google.cloud.tools.jib'
jib {
from {
image = 'openjdk:alpine'
}
}
...
}