Skip to content
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

BundleTaskExtension$BuildAction adds undeclared inputs to jar tasks #5279

Closed
clayburn opened this issue Jun 8, 2022 · 2 comments · Fixed by #5280
Closed

BundleTaskExtension$BuildAction adds undeclared inputs to jar tasks #5279

clayburn opened this issue Jun 8, 2022 · 2 comments · Fixed by #5280
Assignees
Milestone

Comments

@clayburn
Copy link

clayburn commented Jun 8, 2022

Discovered in: ben-manes/caffeine#728. The BuildAction class in the BundleTaskExtension is affecting the output of the jar task by changing the manifest based on certain properties but not declaring them as inputs.

This was noticed in ben-manes/caffeine#728 regarding the archiveVersion of the jar task. In this project, the jar task was made cacheable. Before that, the task would be considered out of date in the below scenario, since the name of the output file had changed. But when the jar task is made cacheable, the output file name is not considered as part of the cache key, so an invalid cache hit results in a jar without the newer version.

archiveVersion is just one example in this action. It appears there are other properties in this action that are effectively inputs but are not declared.

To reproduce:

  1. Checkout caffeine @ 340e9840.
  2. ./gradlew clean :caffeine:jar
  3. unzip -p caffeine/build/libs/caffeine-3.1.2-SNAPSHOT.jar META-INF/MANIFEST.MF | grep Bundle-Version
  4. Verify the Bundle-Version is 3.1.2.SNAPSHOT
  5. ./gradlew :caffeine:jar -Prelease
  6. unzip -p caffeine/build/libs/caffeine-3.1.2.jar META-INF/MANIFEST.MF | grep Bundle-Version
  7. Verify the Bundle-Version is still 3.1.2.SNAPSHOT, when the desired outcome is 3.1.2
ben-manes added a commit to ben-manes/caffeine that referenced this issue Jun 8, 2022
The gradle-build-action uses read only caching on dev branches and
produces a job summary. This causes some noise and slow down, so
revert to the old behavior.

The bnd plugin does not declare its inputs so task caching for
a snapshot/release jar can produce incorrect OSGi version metadata.
The version is now an explicit input to avoid this mistake.

Fixes #728 (bndtools/bnd#5279)
@bjhargrave bjhargrave self-assigned this Jun 14, 2022
@bjhargrave bjhargrave added this to the 6.4 milestone Jun 14, 2022
bjhargrave added a commit to bjhargrave/bnd that referenced this issue Jun 14, 2022
If Bundle-SymbolicName and/or Bundle-Version are not specified in the
bnd instructions, then BundleTaskExtension will set default values
based upon the Jar task's archiveBaseName, archiveClassifier, and
archiveVersion properties. However, these Jar task properties are not
considered inputs to the Jar task. They are just considered as
parts of the archiveFile property which is an output property.

Setting the defaults as input properties means that Gradle will consider
them as part of the build cache key. This is important since the values
can end up in the build jar's manifest.

Fixes bndtools#5279

Signed-off-by: BJ Hargrave <bj@hargrave.dev>
@bjhargrave
Copy link
Member

@clayburn Thanks for the bug report.

I have a fix PR #5280 for Bnd 6.4. In the meantime, here is a workaround for your build that will work with Bnd 6.3:

diff --git a/caffeine/build.gradle b/caffeine/build.gradle
index 260e0e4e..a30284e1 100644
--- a/caffeine/build.gradle
+++ b/caffeine/build.gradle
@@ -87,6 +87,9 @@ tasks.named('jar').configure {
   dependsOn compileCodeGenJava
   manifest {
     attributes 'Bundle-SymbolicName': 'com.github.ben-manes.caffeine'
+    attributes 'Bundle-Version': aQute.bnd.version.MavenVersion.parseMavenString(project.version.toString())
+        .getOSGiVersion()
+        .toString()
     attributes 'Import-Package': ''
     attributes 'Export-Package': [
       'com.github.benmanes.caffeine',

@clayburn
Copy link
Author

Awesome, thanks for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants