Can I use Grape to load modules in Groovy?

I am writing my first automation script in groovy and I ended up at a checkpoint. When using the AntBuilder class to run sshexec (), I run the following error:

: Problem: failed to create task or type sshexec Cause: the class org.apache.tools.ant.taskdefs.optional.ssh.SSHExec was not found. This looks like one of Ant optional components. Action: Check that the appropriate optional JAR exists in -ANT_HOME\lib -the IDE Ant configuration dialogs Do not panic, this is a common problem. The commonest cause is a missing JAR. This is not a bug; it is a configuration problem 

So far, the best I have found for this is to use

 Grape.grab(group : "com.jcraft", module : "jsch", classLoader : this.class.classLoader.rootLoader) Grape.grab(group:"ant", module:"ant-jsch", classLoader:this.class.classLoader.rootLoader) 

to download the necessary modules. However, I would like to exclude the delay time of Grape loading banks from the remote Maven repository.

Is there a way to load and save modules for future use, perhaps in JAVA_PATH or something like that?

+4
source share
3 answers

Adding the required jars to% ANT_HOME% and% GROOVY_HOME% does not work.

The solution is to put the banks in% USERPROFILE% .groovy \ lib - after which Grape calls are no longer needed. Hope this is helpful to others with the same problem.

Thanks to Dave for finding me on the right track.

+1
source

Use Grape annotations to load script dependencies at runtime:

 @Grapes([ @Grab(group='org.apache.ant', module='ant-jsch', version='1.8.3'), @GrabConfig(systemClassLoader=true) ]) def ant = new AntBuilder() ant.sshexec(host:"somehost", username:"yo", password:"dude", command:"ls") 

If you are behind a firewall, you can also configure the location of your Maven repository:

 @GrabResolver(name="my-repo", root="http://my.hostname/maven/repo") 

The final tip, the groovy.grape.autoDownload property can be used to control whether the grapes make a remote download or just use their cached files.

 groovy -Dgroovy.grape.autoDownload=false myscript.groovy 
+2
source

Assuming that your code will only run on a few computers, I would create a grapeConfig.xml file and set ivy.cache.ttl.default to about 30 days. This will tell Grape that if you have a dependency that uses a version range to check remote repositories for updated dependencies every 30 days. See this post for more details.

0
source

Source: https://habr.com/ru/post/1411811/


All Articles