Gradle Workspace Plugin - Run task before bnd-setup

Note: copied from Google groups after I read this is the new shiny place for questions. Thanks for the setup.

Hello everyone

I am using biz.aQute.bnd.workspace Gradle plugin and I need to execute another plugin before bnd is setup.

In detail: I want to create a extension for the Openliberty appserver and therefor I am using a LocalIndexedRepo which references the API/SPI provided by the runtime. When pointing at an existing Openliberty installation this works fine, but I want to use the Openliberty Gradle plugin to setup the runtime before the build.
I havent been able to tell the LocalIndexedRepo to put the index.xml to another location other than the openliberty installation-root (I tried using the locations attribute without success) and this causes the root folder of the server to be created by the LocalIndexedRepo before running the installLiberty task from the Liberty Plugin. The installLiberty task on the other hand skips when the servers root folder exits because it thinks it is already installed.

I tried to run the liberty installation after the configuration phase using this

// Gradle Kotlin-DSL, in case you wonder
tasks {

But for some reason (I assume the bnd-workspace plugin from settings.gradle is doing something) the LocalIndexedRepo is still initialized before.

Any ideas how I can hook into the setup before anything of bnd happens?

As usual, “every problem in software can be solved be a level of indirection”

I just moved the liberty installation folder to a subfolder of the LocalIndexedRepo and included the dirs I needed

-plugin.30.liberty: \
    aQute.bnd.deployer.repository.LocalIndexedRepo; \
        name = "Liberty Runtime"; \
        readonly = true; \
        pretty = true; \
        local = "${build}/liberty/"; \
        onlyDirs = "wlp/lib,wlp/dev/api/ibm,wlp/dev/spi/ibm"

Still, I havent found a way to execute the liberty plugin prior to a Bnd task.

The Bnd workspace is initialized before any tasks are configured since the Bnd Gradle plugins need to know all the projects in the Bnd workspace and their -buildpath and -testpath dependencies (which can come from repositories configured in the Bnd workspace) so that the gradle build can be properly configured.

So there is no way to execute a build task before the Bnd Gradle plugins have configured the build tasks :slight_smile:

You can, of course, make sure a task is executed before another task is executed. But no task can be executed before all tasks are configured. And the Bnd workspace, including the repositories, must be initialized in order to configure the tasks.

You can hook into the Bnd workspace initialization, see gradle.ext.bndWorkspaceConfigure for how we modify some Bnd workspace properties before the Bnd Gradle plugins cause the Bnd workspace to be initialized. But at this point, you cannot execute any gradle tasks since there are none ready to execute as we are still early in the configuration phase (running settings.gradle) of the gradle build.

Thanks for clarifying. Then I might just roll my own code to setup download and extract the openliberty distribution using this hook. Or I just hook it into the gradlew scripts (it is a one time setup anyways).

I think that since you do not actually need to modify the Bnd workspace object, I would just write whatever code you need in settings.gradle to execute before you apply the biz.aQute.bnd.workspace plugin. You don’t need to use the bndWorkspaceConfigure hook.