mockito / shipkit

Toolkit for shipping it used by Mockito library
http://shipkit.org
MIT License
158 stars 35 forks source link

fix UpgradeDependencyPlugin for gradle 4.5.1 #649

Closed epeee closed 6 years ago

epeee commented 6 years ago

fixes #641 and add gradle 4.5.1 to set of gradle versions used for integration testing.

mockitoguy commented 6 years ago

Curious: why does the order matter / how does this particular change fix the issue?

epeee commented 6 years ago

Let's assume we do have 3 plugins: PluginA, PluginB and PluginC and the following implementations:

public class PluginA implements Plugin<Project> {

    @Override
    public void apply(Project project) {
        project.getPlugins().apply(PluginB.class);
    }
}
public class PluginB implements Plugin<Project> {

    @Override
    public void apply(Project project) {
        project.getPlugins().apply(PluginC.class);
    }
}
public class PluginC implements Plugin<Project> {

    @Override
    public void apply(Project project) {
        PluginA pluginA = project.getPlugins().apply(PluginA.class);
        project.getLogger().lifecycle(pluginA.toString());
    }
}

and we do apply plugin: PluginA e.g. in our gradle script.

Prior to Gradle 4.5 this did work. Starting from Gradle 4.5 this will fail with a NullPointer at pluginA.toString() of PluginC.apply.

Replace PluginA by GitOriginPlugin, PluginB by ShipkitConfigurationPlugin and PluginC by InitPlugin and you will see the same problem in shipkit.

Ad how this change fixes it: If we are applying ShipkitConfigurationPlugin first, then we won't get the nullpointer in InitPlugin because GitOriginPlugin is not applied yet and project.getPlugins().apply(GitOriginPlugin.class) does not return null.