I have a Java application that uses Maven, so the Maven POM file (pom.xml) lists all of the dependencies needed to compile and run the application.
I'd like to use groovy during my development and testing and then plug in the code into the Java files when I'm done. I haven't done this yet so it might not be feasible but if it is, that is what I'd like to try and do.
I would like to know if there is a function I can call that will read my pom.xml file and add all of the dependencies to my classpath so I can just import the packages that I need and goovy will already have them loaded (or at least know where to load them).
The groovy script might look like this:
addAllPomDependenciesToMyClasspath();
import my.code.pkg1;
import my.more.code.pkg2;
(new ClassInMyCode()).doCoolStuff();
Without this, I need to specify all my jars on the CLASSPATH and it would look something like this (I haven't yet done this because there are too many dependencies).
#!/bin/sh
groovy -cp "../lib1/target/MyJar1.jar:../lib2/target/MyJar2.jar:$HOME/.m2/repository/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar: KEEP LISTING THESE UNTIL ALL DEPENDENCIES ARE INCLUDED"
Perhaps a better solution would be just to create a gradle file. Let me know if that is the preferred way (if there is no way to autoload all of the maven dependencies).
What have I tried
I've tried searching for solutions and found several ways to add your dependencies to the class path but they don't answer my question.
Some results were:
How to add multiple jars to the classpath of groovyConole/groovysh?
How do I auto load a database jar in Groovy without using the -cp switch?
Including all the jars in a directory within the Java classpath
I'm guessing there is a "groovy" way to do this that approaches the problem differently and that is why I haven't found an answer to this question.
Misc Notes
(Q) How can I add multiple jar files to my groovy classpath? (A) Use "-cp jar1;jar2" (in Windows use semi-colons to separate the names of the jar files, and in Unix use colons to separate the filenames. See https://stackoverflow.com/a/219801/3281336