28

I've done web search for "plugin request for plugin already on the classpath must not include a version site:stackoverflow.com" and found nothing that particular. Search for "plugin request for plugin already on the classpath must not include a version" (w/out SO) found: https://discuss.gradle.org/t/error-plugin-already-on-the-classpath-must-not-include-a-version/31814 where I've read in answers e.g.:

I didn’t find any reference to this use case in Grade plugins documentation.

The error

Build file '/Users/username/github/OpCon/app/build.gradle' line: 4 Error resolving plugin [id: 'com.android.application', version: '3.4.1']

Plugin request for plugin already on the classpath must not include a version

appears in 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

I don't understand, classpath 'com.android.tools.build:gradle:3.5.2' does not seem to include 'com.android.application'... "classpath" has only one occurrence if searched in the project.

ADDED:

Interestingly on https://maven.google.com/web/index.html I can find 'com.android.tools.build:gradle:3.5.2' but no 'com.android.application' branch.

ADDED 2: I've downloaded (quite many files actually was downloaded for some reason) by command taken from here 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'

found path com.android.tools.build:gradle in file manager and looked inside only jar there:

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

So there is a mention gradle plugin com.android.application in jar META-INF.

File com.android.application.properties is one liner: implementation-class=com.android.build.gradle.AppPlugin.

Web search for "implementation class java" finds info on interfaces. In wiki 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.

So gradle plugin could be an interface? How can I dig in further?

Alex Martian
  • 3,423
  • 7
  • 36
  • 71

5 Answers5

36

Gradle doesn't allow multiple versions of a plugin to be present on the classpath. So if you have a multi module build, there could be a chance that more than one module has declared the same plugin with a different version.

To fix this, you will need to specify a single version in a single place i.e settings.gradle

For example, you will put the following in settings.gradle

pluginManagement {
  plugins {
    id 'org.springframework.boot' version "2.3.3.RELEASE"
    id 'io.spring.dependency-management' version '1.0.10.RELEASE'
  }
}

And then in the individual module gradle files, you will do the following (no version mentioned)

plugins {
  id 'org.springframework.boot'
  id 'io.spring.dependency-management'
}

Just for the record, the error mentioned in the question may also show up with this message

plugin was loaded multiple times in different subprojects, which is not supported and may break the build

Abbas Gadhia
  • 14,532
  • 10
  • 61
  • 73
  • I'm trying to create a multi-module project from many existing single projects. Problem is, I cannot change the gradle configuration of the existing single projects. How could I try to solve this by changing only the new top layered gradle project? – Henrique de Sousa Dec 10 '20 at 16:28
6

I was facing same problem, I was using spring boot with plugins as follows

plugins {
    id 'org.springframework.boot' version '2.2.0.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
    id 'war'
}

Since this plugin was present in one dependency gradle was complaining about it. I simply removed those dependencies and it worked:

plugins {
    id 'java'
    id 'war'
}
3

Put configuration into build.gradle in the root project with apply false.

plugins {
    id 'org.springframework.boot' version "2.5.1" apply false
    id 'io.spring.dependency-management' version '1.0.11.RELEASE' apply false
}

Then you can just put it everywhere without the version

plugins {
    id 'org.springframework.boot'
    id 'io.spring.dependency-management'
}

More information: ->Example 3. Applying plugins only on certain subprojects

Ghandhikus
  • 839
  • 2
  • 9
  • 12
  • This worked for me. Thank you For those who use versions catalogs, you can put in build.gradle (project) plugins { alias googleLibs.plugins.firebase apply false } and then in app build.gradle plugins { alias googleLibs.plugins.firebase } – Huan Jun 09 '22 at 14:56
3

For me, it was enough to have this in the project-level build.gradle without mentioning the version:

plugins {
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.android.library) apply false
    alias(libs.plugins.kapt) apply false
    alias(libs.plugins.parcelize) apply false
    alias(libs.plugins.kotlin) apply false
    alias(libs.plugins.navigation) apply false
    alias(libs.plugins.sonarqube) apply false
    alias(libs.plugins.google.services) apply false
    alias(libs.plugins.crashlytics) apply false
}

And then in each module-level build.gradle have the plugins that you want to apply:

plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin)
    alias(libs.plugins.kapt)
    alias(libs.plugins.parcelize)
    alias(libs.plugins.realm)
    alias(libs.plugins.navigation)
    alias(libs.plugins.google.services)
    alias(libs.plugins.crashlytics)
}

Please note that I'm using Gradle Versions catalog

noloman
  • 11,411
  • 20
  • 82
  • 129
0

I had the same issue,

 What went wrong:
Error resolving plugin [id: 'com.github.davidmc24.gradle.plugin.avro', version: '1.6.0']
> Plugin request for plugin already on the classpath must not include a version

thought to apply the changes suggested by https://stackoverflow.com/users/638670/abbas-gadhia in answer https://stackoverflow.com/a/63850224/1503163 and that worked fine too.

But just revisited my issue and realised in my setup the problem was different versions of gradle.

I had gradle locally installed with version 7.3.2 however the project was supposed to be build with gradle wrapper, which was pointing to version 7.6 And it worked perfectly fine with version 7.6

So, double check your gradle versions. Otherwise, the top answer is the solution to define your plugins version in settings.gradle and then use the plugins in your modules without specifying version.

Sanjay Bharwani
  • 3,317
  • 34
  • 31