Hi,
I am trying to build OSGi bundles using Gradle. The crucial feature of an OSGi bundle is its metadata, which is contained in the jar’s META-INF/MANIFEST.MF
. So when I compile a bundle against bundles from other project
modules, the only way for the OSGi tool to generate the correct metadata is for Gradle to place the dependent jars on the compile classpath.
Gradle seems to think that putting these projects’ build/classes/*/main
directories on my compile classpath instead of the jars is a better idea somehow. Gradle is WRONG.
Can someone tell me how to convince Gradle to put the jars on the classpath instead please? I am assuming that it must involve adding some “variant attributes” to a particular Configuration
, but nothing I have tried so far has made any difference.
(Pauses to SUMMON SATAN )
I have just discovered that one thing does make a difference. Is there any reason why
invoking this code in a Gradle plugin’s apply()
handler:
myConfiguration
.attributes { attrs ->
// Set variant attributes suitable for compile classpath
}.withDependencies { deps ->
// Add some extra dependencies programmatically.
}
should behave any differently from:
myConfiguration
.withDependencies { deps ->
// Add some extra dependencies programmatically.
}.attributes { attrs ->
// Set variant attributes suitable for compile classpath
}
please? I would expect these two to be equivalent, because in both cases the new attributes will be added immediately, but the extra dependencies won’t be added until my configuration is used for dependency resolution, However, the second one appears to be doing what I want whereas the first one does not, and I have absolutely NO IDEA why?!
Is this an expected feature of Gradle’s programming model???
Can anyone explain what is happening here please? (My plugin must remain compatible with Gradle 6.8+.)
Thanks for any help here
Cheers,
Chris
Edit: Actually, it’s possible that neither case is really doing what I want; it’s just that executing the Gradle tasks “clean classes
” together has a different result than executing “clean anotherTask
” followed by “classes
”. I suspect Gradle doesn’t know what it’s doing here any more than I do…