无法应用插件 ‘com.google.protobuf’

huangapple go评论80阅读模式
英文:

Failed to apply plugin 'com.google.protobuf'

问题

我正在尝试排除插件构建脚本中的错误。我能够在IntelliJ IDEA内部运行此脚本,但当我尝试从命令行构建时,会出现异常。

我已经将构建脚本简化为如下所示的最小化形式:

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'
}

当我尝试使用这个脚本进行构建时,会出现以下错误:

$ 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)'

如果我只将以下行注释掉,我可以让所有这些工作正常:

```groovy
id 'com.google.protobuf' version '0.8.6'

由于我对Gradle和Java不太熟悉,我不知道如何解释异常的堆栈跟踪信息。

英文:

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 &#39;com.google.protobuf:protobuf-gradle-plugin:0.8.6&#39;
    }
}

plugins {
    id &#39;java&#39;
    id &#39;org.jetbrains.intellij&#39; version &#39;0.3.12&#39;
    id &quot;maven&quot;
    id &quot;de.undercouch.download&quot; version &quot;3.2.0&quot;
    id &quot;com.google.protobuf&quot; version &quot;0.8.6&quot;
    id &quot;idea&quot;
}

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 &#39;/Users/erikengheim/Development/Java/experiment/build.gradle&#39; line: 17

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

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

id &quot;com.google.protobuf&quot; version &quot;0.8.6&quot;

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

答案1

得分: 9

你应该使用最新版本的 protobuf-gradle-plugin,即 0.8.13。它要求至少使用 Gradle 5.6 和 Java 8。更新你的构建脚本:

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

还有这一行:

id "com.google.protobuf" version "0.8.13"
英文:

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 &#39;com.google.protobuf:protobuf-gradle-plugin:0.8.13&#39;
  }
}

and this line:

id &quot;com.google.protobuf&quot; version &quot;0.8.13&quot;

答案2

得分: 2

以下是您要求的翻译内容:

对我而言,我遇到了这个错误:在项目评估期间无法应用 com.google.protobuf 插件。必须先将 Java 插件或其中一个 Android 插件应用于项目

我通过在根项目的 Gradle 插件中在 id &quot;com.google.protobuf&quot; version &quot;0.9.2&quot; 之前添加了 id &#39;java&#39; 来修复它。

plugins {
    id &#39;com.android.application&#39; version &#39;7.4.1&#39; apply false
    id &#39;com.android.library&#39; version &#39;7.4.1&#39; apply false
    id &#39;org.jetbrains.kotlin.android&#39; version &#39;1.8.10&#39; apply false
    id &quot;org.jetbrains.kotlin.plugin.serialization&quot; version &quot;1.8.10&quot;
    id &#39;java&#39;
    id &quot;com.google.protobuf&quot; version &quot;0.9.2&quot;
    id &#39;com.google.dagger.hilt.android&#39; version &#39;2.45&#39; apply false
}
英文:

For me, I was getting the error: 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.

I fixed it by adding id &#39;java&#39; before id &quot;com.google.protobuf&quot; version &quot;0.9.2&quot; in root project gradle plugins.

plugins {
    id &#39;com.android.application&#39; version &#39;7.4.1&#39; apply false
    id &#39;com.android.library&#39; version &#39;7.4.1&#39; apply false
    id &#39;org.jetbrains.kotlin.android&#39; version &#39;1.8.10&#39; apply false
    id &quot;org.jetbrains.kotlin.plugin.serialization&quot; version &quot;1.8.10&quot;
    id &#39;java&#39;
    id &quot;com.google.protobuf&quot; version &quot;0.9.2&quot;
    id &#39;com.google.dagger.hilt.android&#39; version &#39;2.45&#39; apply false
}

答案3

得分: 0

root build.gradle.kts

buildscript {
    repositories {
        mavenLocal()
        google()
        mavenCentral()
        maven(uri("https://jitpack.io"))
    }

    dependencies {
        //...
        classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.18")
    }
}

app

plugins {
    id("com.android.library")
    id("kotlin-android")
    kotlin("kapt")
    id("kotlin-parcelize")
    kotlin("plugin.serialization")
    id("com.google.protobuf") //remove version
}

remove version

id "com.google.protobuf"

OR Kotlin DSL

id("com.google.protobuf")
英文:

root build.gradle.kts

buildscript {
    repositories {
        mavenLocal()
        google()
        mavenCentral()
        maven(uri(&quot;https://jitpack.io&quot;))
    }

    dependencies {
        //...
        classpath(&quot;com.google.protobuf:protobuf-gradle-plugin:0.8.18&quot;)
    }
}

app

plugins {
    id(&quot;com.android.library&quot;)
    id(&quot;kotlin-android&quot;)
    kotlin(&quot;kapt&quot;)
    id(&quot;kotlin-parcelize&quot;)
    kotlin(&quot;plugin.serialization&quot;)
    id(&quot;com.google.protobuf&quot;) //remove version
}

remove version

id &quot;com.google.protobuf&quot;

OR Kotlin DSL

id(&quot;com.google.protobuf&quot;)

huangapple
  • 本文由 发表于 2020年10月7日 20:36:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/64244178.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定