Open abstratt opened 2 days ago
@bjhargrave any idea how much work this will be?
This has long been a known concern and there is a workaround. See https://github.com/bndtools/bnd/tree/master/gradle-plugins#gradle-configuration-cache-support
Certain users of Bnd need access to the open-ended properties in the Gradle Project object.
One can do:
tasks.named("jar") {
bundle {
properties.put("project.group", provider({project.group}))
}
}
for each Gradle Project property they need to use. But sometimes the list of needed properties is not obvious due to Bnd's support for including other bnd files and macros, etc. So this could be a trail-and-error process which can break when a user modifies a bnd file and not the gradle build file.
A possible solution could be to change:
to something like:
MapProperty<String, Object> projectProperties = objects.mapProperty(String.class, Object.class)
.convention(project.provider(() -> project.getProperties()));
properties.convention(Maps.of("project", projectProperties));
This would require the projectProperties MapProperty to fully collect all the Gradle Project properties when the provider is called. I don't know if it does an exhaustive collection or only collects the keys used during configuration (which are zero in this case since the MapProperty is not called until execution time). Since Gradle Projects have dynamic properties, I am not confident this will happen. But perhaps you can shed some light on this and suggest how to collect all Gradle Project properties at (the end of) configuration time so their values could be used at execution time.
Plugins should not access a task's project at execution time. This will be deprecated in 8.12, and will be forbidden in a future release. One case:
https://github.com/bndtools/bnd/blob/4550adf924c46d7c5860bbedadc22ea8f946dc11/gradle-plugins/biz.aQute.bnd.gradle/src/main/java/aQute/bnd/gradle/AbstractBndrun.java#L345
Context: https://github.com/gradle/gradle/issues/30860