gradle protobuf plugin not functioning - gradle

I am using the below mentioned protobuf gradle plugin in one project where its working fine but when I referenced the same plugin in a different project, 'gradle clean' is consistently giving me the error copied below:
relevant parts of build.grade (v3.4)
apply plugin: 'com.google.protobuf'
buildscript {
repositories {
mavenCentral()
mavenLocal()
jcenter()
}
dependencies {
// classpath "net.ltgt.gradle:gradle-errorprone-plugin:0.0.9"
// classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.0'
}
}
def grpcVersion = '1.1.2'
dependencies {
compile "io.grpc:grpc-netty:${grpcVersion}"
compile "io.grpc:grpc-protobuf:${grpcVersion}"
compile "io.grpc:grpc-stub:${grpcVersion}"
}
protobuf {
protoc {
Artifact = 'com.google.protobuf:protoc:3.2.0'
}
plugins {
grpc {
Artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
}
}
generateProtoTasks {
all()*.plugins {
grpc {
// To generate deprecated interfaces and static bindService method,
// turn the enable_deprecated option to true below:
option 'enable_deprecated=false'
}
}
}
}
error when I run gradle clean
* What went wrong:
Could not compile build file '/xyz/xyz/build.gradle'.
> startup failed:
build file '/xyz/xyz/build.gradle': 102: you tried to assign a value to the class 'org.gradle.api.component.Artifact'
# line 102, column 9.
Artifact = 'com.google.protobuf:protoc:3.2.0'
^
build file '/xyz/xyz/build.gradle': 106: you tried to assign a value to the class 'org.gradle.api.component.Artifact'
# line 106, column 13.
Artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
I have tried protobuf plugins 0.8.0. and 0.8.1 but both give the same error. v0.8.0 works as is in a different project. Any thoughts on how to troubleshoot this further would be appreciated.

It should be artifact, not Artifact. The latter is a class that you try to assign to which will not work, the former is a property you assign to.

Related

buildSrc Version script object not being added root buildScript or any project context

i have a simple buildSrc configuration for dependency versions
a buildSrc/gradle.build.kts:
repositories {
jcenter()
}
plugins {
`kotlin-dsl`
}
dependencies {
implementation(kotlin("script-runtime"))
}
I would like to point out that my kotlin script wouldnt work at all without the script-runtime dependency and I have never seen any documentation saying its required but once i added it an error went away:
"No script runtime was found in the classpath: class 'kotlin.script.templates.standard.ScriptTemplateWithArgs' not found. Please add kotlin-script-runtime.jar to the module dependencies."
Then i have a simple object script buildSrc/src/main/java/Versions.kts
object Versions {
val kotlin = "1.3.61"
val kotlinFrontentPlugin = "0.0.45"
}
Doesnt get much simpler.
Then in my root project i have:
build.gradle.kts:
buildscript {
repositories {
google()
mavenCentral()
jcenter()
maven("https://plugins.gradle.org/m2/")
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
classpath("org.jetbrains.kotlin:kotlin-frontend-plugin:${Versions.kotlinFrontendPlugin}")
}
}
This is all just straight up copy and paste. but all i can get is:
Line 12: classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}")
^ Unresolved reference: kotlin
Line 13: classpath("org.jetbrains.kotlin:kotlin-frontend-plugin:${Versions.kotlinFrontendPlugin}")
^ Unresolved reference: kotlinFrontendPlugin
Does buildSrc just no longer work in builds anymore or is there yet some other undocumented setting or action i need to take?
Found the issue. I accidentally named my object as a script
Versions.kts when it needed to be Versions.kt

I got an error using this build.grafle file and don't know how to fix it

Here's the Error:
FAILURE: Build failed with an exception.
Where: Build file '/home/wieland/GitGradlePackaging/build.gradle' line: 22
What went wrong: A problem occurred evaluating root project 'GitGradlePackaging'.
Could not get unknown property 'org' for object of type org.gradle.api.internal.initialization.DefaultScriptHandler.
And Here's my build.gradle File:
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/4.6/userguide/tutorial_java_projects.html
*/
//From example: http://mrhaki.blogspot.co.at/2015/04/gradle-goodness-use-git-commit-id-in.html
buildscript {
repositories {
jcenter()
}
dependencies {
//Add dependencies for build script, so we can access Git from our build script
classpath 'org.ajoberstar:grgit:1.1.0'
}
def git = org.ajoberstar.grgit.Grgit.open(file('.'))
//To save Githash
def githash = git.head().abbreviatedId
}
plugins {
// Apply the java plugin to add support for Java
id 'java'
// Apply the application plugin to add support for building an application
id 'application'
// Apply the groovy plugin to also add support for Groovy (needed for Spock)
id 'groovy'
id 'distribution'
}
// Set version
project.version = mainProjectVersion + " - " + githash
project.ext.set("wholeVersion", "$project.version - $githash")
project.ext.set("buildtimestamp", "2000-01-01 00:00")
def versionfilename = "versioninfo.txt"
def GROUP_DEBUG = 'Debug'
// Task to print project infos
task debugInitialSettings {
group = GROUP_DEBUG
doLast {
println 'Version: ' + project.wholeVersion
println 'Timestamp: ' + project.buildtimestamp
println 'Filename: ' + project.name
}
}
// To add the githash to zip
task renameZip {
doLast {
new File ("$buildDir/distributions/$project.name-${project.version}.zip")
.renameTo ("$buildDir/distributions/$project.name-${project.wholeVersion}.zip")
}
}
distZip.finalizedBy renameZip
// To add the githash to tar
task renameTar{
doLast {
new File ("$buildDir/distributions/$project.name-${project.version}.tar")
.renameTo ("$buildDir/distributions/$project.name-${project.wholeVersion}.tar")
}
}
distTar.finalizedBy renameTar
// Define the main class for the application
mainClassName = 'App'
dependencies {
// This dependency is found on compile classpath of this component and consumers.
compile 'com.google.guava:guava:23.0'
// Use the latest Groovy version for Spock testing
testCompile 'org.codehaus.groovy:groovy-all:2.4.13'
// Use the awesome Spock testing and specification framework even with Java
testCompile 'org.spockframework:spock-core:1.0-groovy-2.4'
testCompile 'junit:junit:4.12'
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
//To generate Testreports as HTML
test {
reports {
junitXml.enabled = false
html.enabled = true
}
}
distributions {
main {
contents {
from { 'build/docs' }
into ('reports') {
from 'build/reports'
}
}
}
}
//To make sure that test and javadoc ran before zip and tar
distTar.dependsOn test
distZip.dependsOn test
distTar.dependsOn javadoc
distZip.dependsOn javadoc
Please keep in mind I have not much knowledge about gradle as I'm just starting to learn it!
Thanks in advance :)
You have to move the githash definition outside the buildscript block
buildscript {
repositories {
jcenter()
}
dependencies {
//Add dependencies for build script, so we can access Git from our build script
classpath 'org.ajoberstar:grgit:1.1.0'
}
}
def git = org.ajoberstar.grgit.Grgit.open(file('.'))
//To save Githash
def githash = git.head().abbreviatedId
The reason is that when the buildscript block is evaluated line by line, its dependencies are not yet loaded. When the rest of the script is evaluated, the dependencies of the buildscript block have already been loaded. This is actually the reason for the buildscript block existence: to be run before the rest of the build and prepare the setup.

Unable to resolve library using Gradle. Resolved using Grape

I'm fairly new to Groovy and I'm trying to wrap my head around Gradle. If I import the org.jvnet.hudson.plugins through Grapes it works perfectly and the dependency is resolved. But if I try to retrieve the dependency using Gradle the dependency is not resolved.
The package org.eclipse.hudson:hudson-core:3.2.1 works with both Gradle and Grape.
A dependency that is not resolved using Gradle
compile 'org.jvnet.hudson.plugins:checkstyle:3.42'
A dependency which is resolved using Grape
#Grab('org.jvnet.hudson.plugins:checkstyle:3.42')
A dependency which is resolved using Gradle
compile 'org.eclipse.hudson:hudson-core:3.2.1'
Error during Gradle build
line 3, column 1.
import hudson.plugins.checkstyle.CheckStyleResultAction;
^
The build.gradle
apply plugin: 'groovy'
repositories {
mavenCentral()
maven {
url "http://repo.jenkins-ci.org/releases/"
}
}
configurations {
ivy
}
sourceSets {
main {
groovy {
srcDirs = ['src/']
}
}
test {
groovy {
srcDirs = ['test/']
}
}
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.11'
compile "org.apache.ivy:ivy:2.4.0"
ivy "org.apache.ivy:ivy:2.3.0"
// Works
compile 'org.eclipse.hudson:hudson-core:3.2.1'
// Does not work
compile 'org.jvnet.hudson.plugins:checkstyle:3.42'
}
tasks.withType(GroovyCompile) {
groovyClasspath += configurations.ivy
}
You're probably not actually downloading the jar you think you are. Looks like the default artifact that comes back from the org.jvnet.hudson.plugins:checkstyle:3.42 dependency is actually a file named checkstyle-3.42.hpi.
To get the jar which contains the classes instead, use:
compile group: 'org.jvnet.hudson.plugins', name: 'checkstyle', version:'3.42', ext: 'jar'
Then that class will be found on your classpath (and you'll be on to locating the next missing dependency).

gRPC gradle :generateProto fails with directory not found when importing other proto definitions

I'm trying to compile some protobuf definitions as a gradle task, but get the following error with no source generation:
* What went wrong:
Execution failed for task ':generateProto'.
> protoc: stdout: . stderr: /Users/ash/IdeaProjects/kotlin/grpc/build/extracted-protos/main: warning: directory does not exist.
service-definitions.proto:10:17: "Empty" is not defined.
service-definitions.proto:10:33: "Empty" is not defined.
service-definitions.proto:15:17: "SimpleRequest" is not defined.
service-definitions.proto:15:41: "SimpleResponse" is not defined.
service-definitions.proto:21:27: "StreamingOutputCallRequest" is not defined.
service-definitions.proto:21:71: "StreamingOutputCallResponse" is not defined.
service-definitions.proto:27:33: "StreamingInputCallRequest" is not defined.
service-definitions.proto:27:69: "StreamingInputCallResponse" is not defined.
service-definitions.proto:34:29: "StreamingOutputCallRequest" is not defined.
service-definitions.proto:34:73: "StreamingOutputCallResponse" is not defined.
service-definitions.proto: warning: Import empty.proto but not used.
service-definitions.proto: warning: Import messages.proto but not used.
This only occurs when I try to compile a definition that imports other definitions. If I remove the service-definitions.proto definition, the others compile and sources are generated.
The protobuf definitions are available from the vertx-grpc examples and I have them in $projectDir/src/main/proto. I've not changed their default build location, so sources are being generated to $projectDir/build/generated/source/proto. Instead of an extracted-protos directory, however, I have extracted-include-protos (probably explains the directory not found error).
Here's my gradle.build file, should it be of use. Note that the gRPC plugin uses the Vert.x artifact rather than the version from io.grpc.. (it's actually just a wrapper over the top of it). I have tried swapping the Vert.x version out for the io.grpc version and get the same error.
group 'grpc'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.3'
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.1"
}
}
apply plugin: 'kotlin'
apply plugin: "java"
apply plugin: "com.google.protobuf"
apply plugin: "idea"
protobuf {
//generatedFilesBaseDir = "$projectDir/build/generated/source/proto"
protoc {
artifact = "com.google.protobuf:protoc:3.3.0"
}
plugins {
grpc {
artifact = "io.vertx:protoc-gen-grpc-java:1.3.0"
}
}
generateProtoTasks {
all().each { task ->
task.plugins {
grpc {}
}
}
}
}
clean {
delete protobuf.generatedFilesBaseDir
}
idea {
module {
sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/grpc")
}
}
sourceSets {
main {
java {
srcDirs += "${protobuf.generatedFilesBaseDir}/main/java"
srcDirs += "${protobuf.generatedFilesBaseDir}/main/grpc"
}
}
}
repositories {
jcenter()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "io.vertx:vertx-core:3.4.2"
compile "io.vertx:vertx-web:3.4.2"
compile "io.vertx:vertx-grpc:3.4.2"
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
apiVersion = "1.1"
languageVersion = "1.1"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
apiVersion = "1.1"
languageVersion = "1.1"
}
}
I've not changed any settings, why is it (a) looking for extracted files in the wrong location, and (b) looking for extracted files at all when importing, given that the necessary definitions are all in the src/main/proto directory?
Okay, after much head scratching, the clue was in the last two lines of the error message:
service-definitions.proto: warning: Import empty.proto but not used.
service-definitions.proto: warning: Import messages.proto but not used.
In my proto definitions, I had specified messages and empty to be in the messages package but hadn't qualified the types when used in the importing definition, which is in the services package. Alas, a simple change and it works:
package services;
service EmptyPingPongService {
// One empty request followed by one empty response.
rpc EmptyCall(Empty) returns (Empty);
}
Becomes:
package services;
service EmptyPingPongService {
// One empty request followed by one empty response.
rpc EmptyCall(messages.Empty) returns (messages.Empty);
}

Bundling all dependencies in .aar file

I have an SDK project that is referencing quit alot of dependencies in gradle. I have to ask the SDK users to add those dependencies when they use the SDK in their projects. The problem is, every time I add some new dependency or replace current dependency with a new one, I'll have to ask the users to make changes as well, which is not a good practice in my opinion. Is there a way to bundle all the dependencies in the .aar. I am generating the artifact file with the following code.
uploadArchives{
repositories.mavenDeployer {
def deployPath = file(getProperty('aar.deployPath'))
repository(url: "file://${deployPath.absolutePath}")
pom.project {
groupId 'myPackageName'
artifactId 'wingoku-io'
version "0.0.6"
}
}
These are my dependencies:
dependencies {
compile 'com.github.nkzawa:socket.io-client:0.5.0'
compile 'com.android.support:cardview-v7:21.+'
compile 'de.greenrobot:eventbus:2.4.0'
}
EDIT:
I have added the following method in uploadArchives method. The size of the artifact file has increased but when I use the .aar file in app project, it can't find the files.
uploadArchives{
repositories.mavenDeployer {
def deployPath = file(getProperty('aar.deployPath'))
repository(url: "file://${deployPath.absolutePath}")
pom.project {
groupId 'myPackageName'
artifactId 'wingoku-io'
version "0.0.6"
}
**configurations.all {
transitive = true
}**
}
UPDATE:
I tried the following code because #aar was generating errors (couldn't find xx.xx.xx.aar on jcenter()). This still fails, the d
compile ('com.github.nkzawa:socket.io-client:0.5.0'){
transitive=true
}
compile ('com.android.support:cardview-v7:21.+#aar'){
transitive=true
}
compile ('de.greenrobot:eventbus:2.4.0'){
transitive=true
}
Dalvik throws following warnings for all classes:
dalvikvm﹕ Link of class 'Lio/wingoku/sdk/Fetch$6;' failed
It eventually throws exception ClassDefNotFound
Regarding your edit
configurations.all {
transitive = true
}
I'm not sure it as any effect.
I think you should write something like this:
dependencies {
compile 'com.github.nkzawa:socket.io-client:0.5.0'{
transitive=true
}
compile 'com.android.support:cardview-v7:21.+#aar'{
transitive=true
}
compile 'de.greenrobot:eventbus:2.4.0'{
transitive=true
}
}
It just say that
cardview is aar to include in this library.
eventbus and socket.io-client are jar lib to include in aar

Resources