Alex Martian
Alex Martian

Reputation: 3812

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

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?

Upvotes: 43

Views: 69203

Answers (9)

Pan JiaCheng
Pan JiaCheng

Reputation: 1

you can have a try like this: in this case the libs is kapt First you need to add this line in project build.gradle

plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose) apply false
// add this line
alias(libs.plugins.kotlin.kapt) apply false}

then to the app build.gradle to add this

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
// add this line
alias(libs.plugins.kotlin.kapt)}

Upvotes: 0

HexedAgain
HexedAgain

Reputation: 1031

Posting this as it might be useful to others willing to dive deeper into the mists of the gradle stack when things go wrong (since errors seem to happen beyond the point that gradle can offer any clues) - you can actually investigate many gradle sync errors by running the assemble task with the debugger.

For a similar type of exception ** I found myself in some file: AlreadyOnClasspathPluginResolver.java, and by stepping into a function it calls before bailing out, namely isPresentOnClasspath and directly evaluating the value it would return in expression evaluator, I could determine the actual version I had on the classpath already (your mileage may vary of course)


** similar exception being: The request for this plugin could not be satisfied because the plugin is already on the classpath with an unknown version, so compatibility cannot be checked.

Upvotes: 0

MEGHA RAMOLIYA
MEGHA RAMOLIYA

Reputation: 1927

If you are using Android studio koala then use below code for parcelize:

1> Add below line in build.gradle.kts(:app)

plugins {
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.jetbrainsKotlinAndroid)
    id("kotlin-parcelize")
}

then sync and build the project again.

Upvotes: 0

ajay
ajay

Reputation: 1000

Navigate to the file android/settings.gradle

update Kotlin version.

   plugins {
        id "dev.flutter.flutter-plugin-loader" version "1.0.0"
        id "com.android.application" version "7.3.0" apply false
        id "org.jetbrains.kotlin.android" version "2.0.0" apply false
}

Upvotes: 0

Sanjay Bharwani
Sanjay Bharwani

Reputation: 4799

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.

Upvotes: 1

noloman
noloman

Reputation: 11975

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

Upvotes: 19

Ghandhikus
Ghandhikus

Reputation: 841

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

Upvotes: 5

Abbas Gadhia
Abbas Gadhia

Reputation: 15110

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

Upvotes: 52

SUBHASH KUMAR RAY
SUBHASH KUMAR RAY

Reputation: 116

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

Upvotes: 6

Related Questions