Re: Bootstrap/pre-processing class?
Michael Stockman <[email protected]> Mon, 13 Jan 2025 07:05:07 -0500
| Newsgroups | gmane.comp.lang.groovy.user |
|---|---|
| Message-ID | <CADLV0W6mvuyNOb4r5=ur_muY_k6E=fJkCqtFFDJYqY-8QXUD1Q@mail.gmail.com> |
Is it possible to just configure Google Artifact Repository as another repository in the grapeConfig.xml? Using username and password authentication setup through GAR, and then use Grab as you normally would? I don't really have much experience with GAR, so I may be very mistaken. Thank you, Mike Stockman Programmer Analyst Integrated Information Technology Services [image: Utica University Logo] Office 315.792.3238 1600 Burrstone Road Utica, NY 13502 utica.edu <https://www.utica.edu/> On Sun, Jan 12, 2025 at 5:45 AM Per Nyfelt <[email protected]> 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.PhoneNumberUtildef 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.PhoneNumberUtildef 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 > >