我已经在网络上搜索“类路径上已经存在的插件的插件请求不得包含版本站点:stackoverflow.com”,但没有发现任何特别的内容。搜索“类路径上已经存在的插件的插件请求不得包含版本”(w/out SO)发现: https://discuss.gradle.org/t/error-plugin-already-on-the-classpath-must-not-include-a-version/31814我在其中读到的答案例如:
I didn’t find any reference to this use case in Grade plugins documentation.
错误
Build file '/Users/username/github/OpCon/app/build.gradle' line: 4 Error resolving plugin [id: 'com.android.application', version: '3.4.1']
block 引用>Plugin request for plugin already on the classpath must not include a version
出现在
IntelliJ IDEA
,build.gradle(OpCon):buildscript { repositories { jcenter() maven { url 'https://maven.google.com/' name 'Google' } google() } dependencies { classpath 'com.android.tools.build:gradle:3.5.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { mavenCentral() maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } repositories { jcenter() maven { url 'https://maven.google.com/' name 'Google' } } } task clean(type: Delete) { delete rootProject.buildDir }
app/build.gradle
:plugins { id 'com.android.application' version '3.4.1' apply true } ... and then other stuff
我不明白,类路径“com.android.tools.build:gradle:3.5.2”似乎不包含“com.android.application”... 如果在项目中搜索“classpath”,则只会出现一次。
添加:
有趣的是https://maven.google.com/web/index.html我可以找到 'com.android.tools.build:gradle:3.5.2' 但没有 'com.android.application' 分支。
添加2: 我已经通过从这里获取的命令下载了(由于某种原因实际上下载了相当多的文件)How can I download a specific Maven artifact in one command line? :
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -DrepoUrl='https://maven.google.com/' -Dartifact='com.android.tools.build:gradle:3.4.1'
找到路径
com.android.tools.build:gradle
在文件管理器中只查看里面的 jar:username$ jar tvf /Users/username/.m2/repository/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.jar | grep application 1115 Wed May 01 20:30:18 MSK 2019 com/android/build/gradle/internal/tasks/ApplicationIdWriterTask$applicationIdSupplier$1.class 55 Wed May 01 20:29:18 MSK 2019 META-INF/gradle-plugins/com.android.application.properties
所以有一个提及
gradle plugin
com.android.application
在 jar 里META-INF
。文件
com.android.application.properties
是一类:implementation-class=com.android.build.gradle.AppPlugin
。网络搜索“implementation class java”可找到有关接口(interface)的信息。在维基 https://en.wikipedia.org/wiki/Interface_(Java) :
An interface in the Java programming language is an abstract type that is used to specify a behavior that classes must implement.
那么 gradle 插件可以是一个接口(interface)吗?我怎样才能进一步挖掘?
最佳答案
Gradle 不允许插件的多个版本出现在类路径中。因此,如果您有一个多模块构建,则可能有多个模块声明了具有不同版本的相同插件。
要解决此问题,您需要在一个位置指定一个版本,即 settings.gradle
例如,您将以下内容放入settings.gradle
pluginManagement {
plugins {
id 'org.springframework.boot' version "2.3.3.RELEASE"
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
}
}
然后在各个模块 gradle 文件中,您将执行以下操作(未提及版本)
plugins {
id 'org.springframework.boot'
id 'io.spring.dependency-management'
}
仅供记录,问题中提到的错误也可能与此消息一起显示
plugin was loaded multiple times in different subprojects, which is not supported and may break the build
关于java - 对已位于类路径上的插件的插件请求不得包含版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60070739/