Home > Mobile >  Gradle plugin must not include version
Gradle plugin must not include version

Time:09-10

I have a multiproject gradle project

  • project_android
    • project_lib
    • app

project-lib is in its own git repository which I added to to project_android using git subtree.

I'm stuck. In order to build project_lib by itself, I need to specify a version for this plugin. If I don't have the version

plugins {
  id 'org.jetbrains.kotlin.jvm'
}

I get this error when building

* What went wrong:
Plugin [id: 'org.jetbrains.kotlin.jvm'] was not found in any of the following sources:

- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
```

So I add a version and then it works

plugins {
  id 'org.jetbrains.kotlin.jvm' version "1.7.10"
}

But now I can't build project_android, here is the error

Error resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.7.10']
> Plugin request for plugin already on the classpath must not include a version

I haven't added this plugin to app so I don't know where it comes from. This is the plugins in project_android/app/build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    // Kotlin Annotation Processing Tool
    id 'kotlin-kapt'
    // Google Services plugin
    id 'com.google.gms.google-services'
    // Navigation
    id 'androidx.navigation.safeargs.kotlin'
    // Performance Monitoring plugin
    id 'com.google.firebase.firebase-perf'
}

One project requires me to add a version. Another requires me not to add a version. What do I do to keep both happy?

CodePudding user response:

Usually when I run into this it's because there is another implementation of that plug-in in one of the other gradle files. Look in your build.gradle project file and/or your gradle settings file to see if another version of 'org.jetbrains.kotlin.jvm' is listed. You may have to play around with deleting it from one of those other files and resyncing the gradle until it works.

CodePudding user response:

I resolved this by using the gradle legacy plugin dsl. In project_lib\build.gradle instead of:

plugins {
  id 'org.jetbrains.kotlin.jvm' version '1.17.10'
}

I instead do this

buildscript {
    repositories {
        gradlePluginPortal()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10"
    }
}

apply plugin: "org.jetbrains.kotlin.jvm"
  • Related