Can I add instructions via properties/macros?

Hi all! I’ve got a Gradle non-workspace bnd build, with a bnd.bnd file. I have a set of libraries that the Gradle build is aware of (via Gradle dependencies), that I want to add to the Bundle-ClassPath, so I intend to use -includeresource statements.

Because the set of dependencies is dynamic, I don’t want to add it to the bnd.bnd. My naïve attempt was to set up a property in the build.gradle:

jar {
    bundle {
        properties = [
            "extraincluderesources": "-includeresource.extra=lib/<name>.jar=<name>-*.jar;lib:=true"
        ]
    }
}

and then simply reference that property in a line of its own, in the bnd.bnd:

${extraincluderesources}

This doesn’t work, with the following warning:

warning: No value specified for key: ${extraincluderesources}. An empty value should be specified as '${extraincluderesources}:' or '${extraincluderesources}=': <<${extraincluderesources}

Obviously I’m being foolish, but what is the right way to dynamically include a list of dependencies?

I would try:

jar {
    bundle {
        properties = [
            "extraincluderesources": "lib/<name>.jar=<name>-*.jar;lib:=true"
        ]
    }
}

Then in the bnd file

-includeresource.extra=${extraincluderesources}

Bnd will expand macros in the value of a property but not the key.

Thanks @bjhargrave, that’s done the trick.

If I extend that beyond what I need at the moment, I think that means I shouldn’t aim for being able to dynamically generate arbitrary -includeresource.extra1=, -includeresource.extra2=, -includeresource.extra3=, … statements - instead, leave a single placeholder and do the hard work of constructing a single value on the Gradle side.

Yes. Since it is a gradle-side issue to determine the set of libraries. No need to clutter the bnd-side.

1 Like