Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying the plugin from a script plugin #97

Closed
bmuschko opened this issue Jul 22, 2018 · 4 comments
Closed

Applying the plugin from a script plugin #97

bmuschko opened this issue Jul 22, 2018 · 4 comments

Comments

@bmuschko
Copy link

Gradle still doesn't support applying a plugin by ID from a script plugin. For example I have the following code in release.gradle:

buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }

    dependencies {
        classpath 'org.ajoberstar.reckon:reckon-gradle:0.8.0'
    }
}

apply plugin: org.ajoberstar.reckon.gradle.ReckonPlugin

Internally, the reckon plugin tries to apply the plugin with ID org.ajoberstar.grgit. I believe this doesn't work in script plugins as you have to apply the plugin by type. The published metadata should probably include the org.ajoberstar.grgit dependency. It is a requirement for this plugin to work properly. Am I missing something?

@ajoberstar
Copy link
Owner

I do have a compile dependency on grgit. I presume the issue here is that I'm applying by ID, instead of by class name?

@bmuschko
Copy link
Author

That's my guess.

@kevin-maskell-moody
Copy link

kevin-maskell-moody commented Oct 23, 2019

I'm fairly certain that this is related to this. Perhaps, @bmuschko can clarify. I'm developing a kotlin plugin that applies reckon, by class (maybe this is the same as applying via a script plugin?), and configures the extension.

This seemed to be working great in test projects and whatnot, where I was blindly applying the reckon plugin, and my plugin had an api dependency on both grgit-gradle and reckon-gradle. I'm not 100% at what point this stopped working, but it should...

val reckonPlugin = ReckonPlugin::class.java
if (!rootProject.pluginManager.hasPlugin(reckonPlugin.name)) {
    rootProject.pluginManager.apply(reckonPlugin)
    configureReckon(rootProject)
}

Suddenly, started seeing:

Failed to apply plugin [class 'org.ajoberstar.reckon.gradle.ReckonPlugin']
Plugin with id 'org.ajoberstar.grgit' not found.

I attempted to directly apply grgit-gradle and added the following to see what was actually applied:

logger.info("Applying reckon gradle plugin to root project")
logger.info("Is org.ajoberstar.grgit applied? - ${rootProject.pluginManager.hasPlugin("org.ajoberstar.grgit")}")
rootProject.plugins.forEach {
    println("Plugin - $it")
}

Got the following output:

Applying reckon gradle plugin to root project
Is org.ajoberstar.grgit applied? - true
Plugin - org.gradle.plugins.ide.idea.IdeaPlugin@1f815831
...
Plugin - org.ajoberstar.grgit.gradle.GrgitPlugin@4887324a

But, I still see the same error.

@kevin-maskell-moody
Copy link

So, I forked reckon and made the simple change of applying grgit-gradle via the plugin's class name. That resolves the issue. I now see an innocuous warning:

Is org.ajoberstar.grgit applied? - false
Plugin - ...
Project :xyz already has a grgit property. Remove org.ajoberstar.grgit from either :xyz or :xyz.

I didn't dig much to see where this was coming from. But, it looks like there are a few bad checks going on and you can easily move to applying the plugin by class name.

Should I create a pull request for this small change or leave it to you?

ReckonPlugin.java:25

Class grgitPlugin = GrgitPlugin.class;
project.getPluginManager().apply(grgitPlugin);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants