Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to apply plugin 'com.google.protobuf'

I am trying to troubleshoot an error in a build script for a plugin. I am able to run this from inside IntelliJ IDEA, but when I try to build from the command line I get an exception.

I have been able to reduce the build script to a bare minimum as seen below:

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

plugins {
    id 'java'
    id 'org.jetbrains.intellij' version '0.3.12'
    id "maven"
    id "de.undercouch.download" version "3.2.0"
    id "com.google.protobuf" version "0.8.6"
    id "idea"
}

When I try to perform a build using this script I get the following errors:

$ gradle buildPlugin

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/erikengheim/Development/Java/experiment/build.gradle' line: 17

* What went wrong:
An exception occurred applying plugin request [id: 'com.google.protobuf', version: '0.8.6']
> Failed to apply plugin 'com.google.protobuf'.
   > Could not create an instance of type com.google.protobuf.gradle.ProtobufSourceDirectorySet.
      > 'void org.gradle.api.internal.file.DefaultSourceDirectorySet.<init>(java.lang.String, java.lang.String, org.gradle.api.internal.file.FileResolver, org.gradle.api.internal.file.collections.DirectoryFileTreeFactory)'

I can get all of this to work if I only comment out the line:

id "com.google.protobuf" version "0.8.6"

I am not very familiar with Gradle or Java, so I don't know how to interpret the stack backtrace of the exception.

like image 230
Erik Engheim Avatar asked May 16 '26 11:05

Erik Engheim


1 Answers

You should use the latest version of protobuf-gradle-plugin which is 0.8.13. It requires at least Gradle 5.6 and Java 8.
Update your build script:

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

and this line:

id "com.google.protobuf" version "0.8.13"
like image 106
Ankit Avatar answered May 19 '26 01:05

Ankit