英文:
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 '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.
答案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 'com.google.protobuf:protobuf-gradle-plugin:0.8.13'
}
}
and this line:
id "com.google.protobuf" version "0.8.13"
答案2
得分: 2
以下是您要求的翻译内容:
对我而言,我遇到了这个错误:在项目评估期间无法应用 com.google.protobuf 插件。必须先将 Java 插件或其中一个 Android 插件应用于项目
。
我通过在根项目的 Gradle 插件中在 id "com.google.protobuf" version "0.9.2"
之前添加了 id 'java'
来修复它。
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
id "org.jetbrains.kotlin.plugin.serialization" version "1.8.10"
id 'java'
id "com.google.protobuf" version "0.9.2"
id 'com.google.dagger.hilt.android' version '2.45' 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 'java'
before id "com.google.protobuf" version "0.9.2"
in root project gradle plugins.
plugins {
id 'com.android.application' version '7.4.1' apply false
id 'com.android.library' version '7.4.1' apply false
id 'org.jetbrains.kotlin.android' version '1.8.10' apply false
id "org.jetbrains.kotlin.plugin.serialization" version "1.8.10"
id 'java'
id "com.google.protobuf" version "0.9.2"
id 'com.google.dagger.hilt.android' version '2.45' 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("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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论