I've been working on a solution, which involves shading Groovy into a fat
JAR.  This approach works well, except for one issue.

When I include an ExtensionModules file (shown below), the custom
extensions function correctly. However, standard Groovy methods, such as
those in EncodingGroovyMethods and DefaultGroovyMethods, are unavailable.
While I could add these standard methods to the ExtensionModules file, I
believe this is not the correct solution.I've reviewed the Groovy source
code, particularly the DGM_LIKE_CLASSES classes, then i was stuck trying to
understand the correct initialization process.

While composing this email, I discovered the dgminfo file, which solved the
problem.  The DgmConverter's main method generates this file during the
build process and packages it into the JAR. This file is then processed
during class loading.
So i used unpack of the maven dependency plugin to extract and repack it
with <Include-Resource> into my fat jar: Works like a charm.

I'm writing this as a solution for anyone else trying to get Groovy 4
working in OSGi until org.apache.groovy:groovy is a Fragment-Host again.

br
Matthias


moduleName=groovy-multi
moduleVersion=4.0.25
extensionClasses=org.apache.groovy.datetime.extensions.DateTimeExtensions,\
org.apache.groovy.dateutil.extensions.DateUtilExtensions,\
org.codehaus.groovy.jsr223.ScriptExtensions,\
org.apache.groovy.sql.extensions.SqlExtensions,\
org.apache.groovy.swing.extensions.SwingExtensions,\
org.apache.groovy.xml.extensions.XmlExtensions,\
org.apache.groovy.nio.extensions.NioExtensions
staticExtensionClasses=org.apache.groovy.datetime.extensions.DateTimeStaticExtensions,\
org.apache.groovy.dateutil.extensions.DateUtilStaticExtensions,\
org.codehaus.groovy.jsr223.ScriptStaticExtensions

On Mon, 10 Feb 2025 at 17:03, Matthias Leinweber <m.leinwe...@datatactics.de>
wrote:

> I am not sure if someone ever tested this... Documentation says to get
> groovy extensions working is that the extension must be in the same class
> path (class loader).
>
> Maybe I am wrong but so fragment host (terrible name imho) is the only
> solution. Or shading a new jar could do the same trick.
>
> What do you think?
>
> Br
>
> Paul King <pa...@asert.com.au> schrieb am Mo., 10. Feb. 2025, 14:25:
>
>> In the following issue we were not certain of the need for
>> Fragment-Host in Groovy 4:
>>
>> https://issues.apache.org/jira/browse/GROOVY-9402
>>
>> It could well be that it is needed.
>>
>> Cheers, Paul.
>>
>> On Mon, Feb 10, 2025 at 10:00 PM Matthias Leinweber
>> <m.leinwe...@datatactics.de> wrote:
>> >
>> > Hi together,
>> >
>> > I am using groovy alot in an osgi container with camel (currently
>> karaf.4.7.7 camel 4.9.1 and groovy 4.0.25)
>> >
>> > Somehow the dateutils overload for the date class seems not to work
>> anymore. In groovy 3.0.9 the bundle was a fragment host and working.... Do
>> I need to do something extra with groovy 4?
>> >
>> > Br Matthias
>>
>

Reply via email to