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

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

Failed to apply plugin 'com.google.protobuf'

问题

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

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

  1. buildscript {
  2. repositories {
  3. mavenCentral()
  4. }
  5. dependencies {
  6. classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.6'
  7. }
  8. }
  9. plugins {
  10. id 'java'
  11. id 'org.jetbrains.intellij' version '0.3.12'
  12. id 'maven'
  13. id 'de.undercouch.download' version '3.2.0'
  14. id 'com.google.protobuf' version '0.8.6'
  15. id 'idea'
  16. }

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

  1. $ gradle buildPlugin
  2. FAILURE: Build failed with an exception.
  3. * Where:
  4. Build file '/Users/erikengheim/Development/Java/experiment/build.gradle' line: 17
  5. * What went wrong:
  6. An exception occurred applying plugin request [id: 'com.google.protobuf', version: '0.8.6']
  7. > Failed to apply plugin 'com.google.protobuf'.
  8. > Could not create an instance of type com.google.protobuf.gradle.ProtobufSourceDirectorySet.
  9. > '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)'
  10. 如果我只将以下行注释掉,我可以让所有这些工作正常:
  11. ```groovy
  12. 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:

  1. buildscript {
  2. repositories {
  3. mavenCentral()
  4. }
  5. dependencies {
  6. classpath &#39;com.google.protobuf:protobuf-gradle-plugin:0.8.6&#39;
  7. }
  8. }
  9. plugins {
  10. id &#39;java&#39;
  11. id &#39;org.jetbrains.intellij&#39; version &#39;0.3.12&#39;
  12. id &quot;maven&quot;
  13. id &quot;de.undercouch.download&quot; version &quot;3.2.0&quot;
  14. id &quot;com.google.protobuf&quot; version &quot;0.8.6&quot;
  15. id &quot;idea&quot;
  16. }

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

  1. $ gradle buildPlugin
  2. FAILURE: Build failed with an exception.
  3. * Where:
  4. Build file &#39;/Users/erikengheim/Development/Java/experiment/build.gradle&#39; line: 17
  5. * What went wrong:
  6. An exception occurred applying plugin request [id: &#39;com.google.protobuf&#39;, version: &#39;0.8.6&#39;]
  7. &gt; Failed to apply plugin &#39;com.google.protobuf&#39;.
  8. &gt; Could not create an instance of type com.google.protobuf.gradle.ProtobufSourceDirectorySet.
  9. &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:

  1. 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。更新你的构建脚本:

  1. buildscript {
  2. repositories {
  3. mavenCentral()
  4. }
  5. dependencies {
  6. classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.13'
  7. }
  8. }

还有这一行:

  1. 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:

  1. buildscript {
  2. repositories {
  3. mavenCentral()
  4. }
  5. dependencies {
  6. classpath &#39;com.google.protobuf:protobuf-gradle-plugin:0.8.13&#39;
  7. }
  8. }

and this line:

  1. 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; 来修复它。

  1. plugins {
  2. id &#39;com.android.application&#39; version &#39;7.4.1&#39; apply false
  3. id &#39;com.android.library&#39; version &#39;7.4.1&#39; apply false
  4. id &#39;org.jetbrains.kotlin.android&#39; version &#39;1.8.10&#39; apply false
  5. id &quot;org.jetbrains.kotlin.plugin.serialization&quot; version &quot;1.8.10&quot;
  6. id &#39;java&#39;
  7. id &quot;com.google.protobuf&quot; version &quot;0.9.2&quot;
  8. id &#39;com.google.dagger.hilt.android&#39; version &#39;2.45&#39; apply false
  9. }
英文:

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.

  1. plugins {
  2. id &#39;com.android.application&#39; version &#39;7.4.1&#39; apply false
  3. id &#39;com.android.library&#39; version &#39;7.4.1&#39; apply false
  4. id &#39;org.jetbrains.kotlin.android&#39; version &#39;1.8.10&#39; apply false
  5. id &quot;org.jetbrains.kotlin.plugin.serialization&quot; version &quot;1.8.10&quot;
  6. id &#39;java&#39;
  7. id &quot;com.google.protobuf&quot; version &quot;0.9.2&quot;
  8. id &#39;com.google.dagger.hilt.android&#39; version &#39;2.45&#39; apply false
  9. }

答案3

得分: 0

root build.gradle.kts

  1. buildscript {
  2. repositories {
  3. mavenLocal()
  4. google()
  5. mavenCentral()
  6. maven(uri("https://jitpack.io"))
  7. }
  8. dependencies {
  9. //...
  10. classpath("com.google.protobuf:protobuf-gradle-plugin:0.8.18")
  11. }
  12. }

app

  1. plugins {
  2. id("com.android.library")
  3. id("kotlin-android")
  4. kotlin("kapt")
  5. id("kotlin-parcelize")
  6. kotlin("plugin.serialization")
  7. id("com.google.protobuf") //remove version
  8. }

remove version

  1. id "com.google.protobuf"

OR Kotlin DSL

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

root build.gradle.kts

  1. buildscript {
  2. repositories {
  3. mavenLocal()
  4. google()
  5. mavenCentral()
  6. maven(uri(&quot;https://jitpack.io&quot;))
  7. }
  8. dependencies {
  9. //...
  10. classpath(&quot;com.google.protobuf:protobuf-gradle-plugin:0.8.18&quot;)
  11. }
  12. }

app

  1. plugins {
  2. id(&quot;com.android.library&quot;)
  3. id(&quot;kotlin-android&quot;)
  4. kotlin(&quot;kapt&quot;)
  5. id(&quot;kotlin-parcelize&quot;)
  6. kotlin(&quot;plugin.serialization&quot;)
  7. id(&quot;com.google.protobuf&quot;) //remove version
  8. }

remove version

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

OR Kotlin DSL

  1. 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:

确定