-
-
Notifications
You must be signed in to change notification settings - Fork 302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugins should not access a task's project at execution time #6346
Comments
@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: bnd/gradle-plugins/biz.aQute.bnd.gradle/src/main/java/aQute/bnd/gradle/AbstractBndrun.java Line 292 in 3f2c1d3
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. |
@abstratt did you notice the question from @bjhargrave ?
|
Actually, such provider would be evaluated at configuration (store) time. However, the value it returns must contain only objects supported by the configuration cache. |
At least you have a workaround. But please beware that (unless you change your implementation's default behavior) builds will soon start producing deprecation warnings if your users do not set the task's own |
I am not sure if I am getting this correctly
Although I can see the utility, the fact that you make your build depend on Gradle seems off. These features won't work in Eclipse, IDEA, or the bnd command line. I think I agree that we should remove the default code I am a nitwit in gradle but could we do this in a build.gradle file in the project that needs this information? Or does this need to be done in the root build.gradle? We're planning to start releasing 7.1 so it would be appreciated if we could expedite this. It would be awkward if all the builds started to have warnings. |
@pkriens This issue is not for Bnd Workspace builds. It is for standard gradle builds where the gradle project uses the biz.aQute.bnd.builder gradle plugin. This type of use can be with a bnd file or with bnd configuration in the project's build.gradle file. Such bnd configuration is used to build a bundle in the gradle project and the bundle may want to reference standard gradle project properties like project.name, project.version, project.description. This is why the default behavior was to use the real gradle project object (DRY) instead of requiring the developer to duplicate this information in the bnd configuration. See some examples: bnd/gradle-plugins/biz.aQute.bnd.gradle/testresources/builderplugin2/build.gradle Lines 50 to 52 in 7d340b3
|
I will note that JUnit5 example already uses the workaround to avoid using the gradle project object at execution time. |
ah, makes sense. Might be stupid but can't the macro expansion happen at configuration time? |
Some could happen but it is difficult to know which bnd macros can be resolved early during gradle configuration time and which bnd macros depend upon information calculated by bnd during gradle execution time when bnd build is done. The bnd gradle plugin would need a feature in bndlib which determines all macros whose value is not affected by build time calculations. Then the bnd gradle plugin could resolve the values for those macros and insert them into the properties map at the end of gradle configuration. The current workaround asks the user to make this determination and load the values into the properties map. |
Also note that the same issue exists for bndruns (run, test, resolve, export) as well as building. The original comment referenced bndrun but I was mostly thinking about building. So I just wanted to highlight that in both cases this issue is present. |
still not completely getting it .. sorry. @abstratt warns us that we will start creating deprecation warnings and finally it won't work anymore. To be sure, if they get this warning they can prevent the warning with the workaround? So we have nothing to do? |
Ok, the plan is:
So it will not be in 7.1 |
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:
bnd/gradle-plugins/biz.aQute.bnd.gradle/src/main/java/aQute/bnd/gradle/AbstractBndrun.java
Line 345 in 4550adf
Context: gradle/gradle#30860
The text was updated successfully, but these errors were encountered: