Thank you! GAR uses its own protocol (artifactory://) and is also tied to GCP credentials so just configuring it as a repository will not work. I'll attempt to create it as an alternative Grab implementation along the lines you outlined in the link instead.
Best regards, Per On 2025-01-13, 14:21, "Paul King" <pa...@asert.com.au <mailto:pa...@asert.com.au>> wrote: It's a long way from being ready for merging but I just created a PR for a very early spike I did a while ago for replacing Ivy with the Maven Artifact Resolver Provider: https://github.com/apache/groovy/pull/2140 <https://github.com/apache/groovy/pull/2140> I don't know if that (when finished) could assist you or whether it gives you one idea of how you could go. As Michael Stockman suggested, you might be able to configure GAR as a repository for Ivy, or an additional Grab implementation as per above might also work. The advantage of using Grab is that it is already plumbed into the compilation process (in terms of adding to the classpath when needed). Hopefully I will get back to looking at that again soon. Paul. On Sun, Jan 12, 2025 at 8:45 PM Per Nyfelt <p...@alipsa.se <mailto:p...@alipsa.se>> wrote: > > Hi, > > One of the companies i work for has moved to Google Artifact Registry (GAR) > which does not work well with @Grab so I am attempting to write an > alternative that uses maven (with some extensions handling GAR communication) > for dependency resolution. > > My problem is that in order for this to work, I have to run the dependency > grabbing code first and then the groovy script. e.g. like this > > String depScript = ''' > def resolver = new se.alipsa.groovy.resolver.DependencyResolver(this) > resolver.addDependency('com.googlecode.libphonenumber:libphonenumber:8.13.26') > ''' > String script = ''' > import com.google.i18n.phonenumbers.PhoneNumberUtil > def phoneNumber = PhoneNumberUtil.getInstance().parse('+46 70 12 23 198', > 'SE') > println "Phone number is ${numberUtil.isValidNumber(phoneNumber) ? '' : 'NOT > '}valid" > ''' > > GroovyScriptEngineImpl groovyScriptEngine = new GroovyScriptEngineImpl() > groovyScriptEngine.eval(depScript) > groovyScriptEngine.eval(script) > > I tried to turn this into an annotation and adding the dependency code in a > static initializer using an ASTTransformation but import statements > are processed before static initializers during compilation so this will not > work. What maybe would work would be to register some "bootstrap" script/class > that is executed before the actual script is processed and adds the > dependencies to the ClassLoader before processing the script > (essentially running the depScript code). > > Then the above could be simplified to: > > String script = ''' > @Lib('com.googlecode.libphonenumber:libphonenumber:8.13.26') > import com.google.i18n.phonenumbers.PhoneNumberUtil > def phoneNumber = PhoneNumberUtil.getInstance().parse('+46 70 12 23 198', > 'SE') > println "Phone number is ${numberUtil.isValidNumber(phoneNumber) ? '' : 'NOT > '}valid" > ''' > i.e. I would only need to change @Grab statements to @Lib statements (@Lib is > the annotation pointing to the GroovyASTTranformation class that would add > the code to the > "bootstrap" class). > > Is there a way to do such a thing? > > Regards, > Per