ajoberstar / reckon

Infer a project's version from your Git repository.
Apache License 2.0
191 stars 28 forks source link

Settings plugin: tag and push task creation could be done a little earlier #200

Closed jnehlmeier closed 11 months ago

jnehlmeier commented 12 months ago

I am working on a settings convention plugin that applies reckon and foojay plugins via code to root project. Also as soon as subprojects are available it applies the base plugin and configures the reckonTagCreate task to depend on check task. However this code seems to run too early as it cannot find the reckonTagCreate task.

The following is what I do

var pluginManager = settings.getPluginManager();
pluginManager.apply(ReckonSettingsPlugin.class);
pluginManager.apply(FoojayToolchainsConventionPlugin.class);

var extensions = settings.getExtensions();
configureReckon(extensions);

settings.getGradle().rootProject(rootProject -> {
  configureRootProject(rootProject);
  rootProject.subprojects(this::configureSubProject);
});

private void configureSubProject(Project subProject) {
    var pluginManager = subProject.getPluginManager();
    pluginManager.apply(BasePlugin.class);
    pluginManager.withPlugin("base", plugin -> {
      subProject.getRootProject().getTasks().named(ReckonSettingsPlugin.TAG_TASK,
          task -> task.dependsOn(subProject.getTasks().named(LifecycleBasePlugin.CHECK_TASK_NAME)));
    });
  }

It seems like that Gradle.rootProject.subprojects runs earlier than Gradle.projectsLoaded, which the reckon settings plugin uses to register its tasks.

Maybe you can check if the above would work if reckon would use Gradle.rootProject instead of Gradle.projectsLoaded since reckon only configures tasks on the root project anyways.

As a workaround I will now also use Gradle.projectsLoaded.