0

I'm having a hard time applying my custom external gradle plugins to an existing multi-module project. My project's structure looks like this:

my-app/
├─ buildSrc/
│  ├─ build.gradle.kts
├─ module1/
│  ├─ build.gradle.kts
├─ module2/
│  ├─ build.gradle.kts
├─ settings.gradle.kts

I've now implemented a couple of custom binary plugins which live in another repository and publishing them to mavenLocal() like so:

Plugin Repo Code

gradlePlugin {
    plugins {
        create("plugin") {
            id = "organization.gradle.my-conventions"
            implementationClass = "organization.gradle.MyConventionsPlugin"
            version = "0.0.1"
        }
        create("plugin2") {
            id = "organization.gradle.my-other-conventions"
            implementationClass = "organization.gradle.MyOtherConventionsPlugin"
            version = "0.0.1"
        }
    }
}

Main Project Code

In my main project, I've configured settings.gradle.kts to resolve plugins from mavenLocal and apply one of the plugins (let's say plugin1) in the build.gradle.kts of module1. This looks like this:

plugins {
  id("organzation.gradle.MyConventionsPlugin") version "0.0.1"
}

This doesn't work though. I end up getting a stacktrace saying:

> Failed to apply plugin class 'org.jetbrains.kotlin.gradle.scripting.internal.ScriptingGradleSubplugin'.
   > Cannot run Project.afterEvaluate(Action) when the project is already evaluated.

I tried the same way of applying the plugins in a non multi-module project (i.e. a single build.gradle.kts) and the plugins are applied as expected. So this most likely has to do with the multi-module aspect of it and some additional config?

pirox22
  • 892
  • 1
  • 14
  • 30
  • It looks like you've made a mistake in the plugin. It's not easy writing a Gradle plugin, so it's understandable! Without looking at the code it's impossible to find out what's wrong, can you update your question to include it? Specifically regarding any code that applies `afterEvaluate { }`. I guess it's doing something like `rootProject.afterEvaluate { }` - but this won't work. – aSemy Feb 22 '22 at 18:14
  • Does this answer your question? [Gradle 7 Migration: Failed to apply PublishPlugin (maven-publish): Cannot run afterEvaluate when the project is already evaluated](https://stackoverflow.com/questions/68586807/gradle-7-migration-failed-to-apply-publishplugin-maven-publish-cannot-run-af) – aSemy Feb 22 '22 at 18:14

0 Answers0