Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 858
Alexei Martianov Avatar asked Feb 05 '20 07:02

Alexei Martianov


3 Answers

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

like image 93
Abbas Gadhia Avatar answered Oct 11 '22 19:10

Abbas Gadhia


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'
}
like image 30
SUBHASH KUMAR RAY Avatar answered Oct 11 '22 20:10

SUBHASH KUMAR RAY


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

like image 39
Ghandhikus Avatar answered Oct 11 '22 20:10

Ghandhikus