Groovy - Grab - download failed - groovy

I have a fresh installation of Groovy 2.1.4 and I'd like to create a script that uses HTTP builder.
I've added the following line at the top of the script:
#Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.6')
When I run the script in GroovyConsole, I get the following error:
1 compilation error:
Exception thrown
VI 01, 2013 12:15:39 ODP. org.codehaus.groovy.runtime.StackTraceUtils sanitize
WARNING: Sanitizing stacktrace:
java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
... (aso) ...
java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar]
When I run the following command on the Windows command line:
grape -V resolve org.codehaus.groovy.modules.http-builder http-builder 0.6
I get the same error, i.e.:
:: problems summary ::
:::: WARNINGS
[NOT FOUND ] commons-logging#commons-logging;1.1.1!commons-logging.jar (0ms)
==== localm2: tried
file:C:\Documents and Settings\Administrator/.m2/repository/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
:: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS
Error in resolve:
Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar]
When I try to resolve commons-logging directly, via the following command:
grape -V resolve commons-logging commons-logging 1.1.1
I get the same error, i.e. not found.
When I instead try to download the latest version, i.e. 1.1.3, via the appropriate command, it works. But even after that, resolving the http-client still fails.
Where's the problem?

Try deleting ~/.m2 directory and also ~/.groovy/grapes directories.
It worked for me.

It looks like your Grape settings are set only to look in your local .m2 directory for the library. Check your grapeConfig.xml configuration file. (If you don't have one, you can create it--it should go in the same directory where your groovysh.history and grapes cache directory are created by Groovy.) You can copy the example file shown on the Groovy Grape reference page.
If that doesn't help, I would try deleting your grapes cache directory and try it again.

My problem was, groovy (v2.4.8) was looking in the maven repository fist (~/.m2/repository/) and finding the pom file but not finding the associated artifact/JAR. Instead of just moving on to the next resolver, which would have succeeded, it just gives up. The workaround would be to remove the pom file, the specific directory cache, or just temporarily rename the repository and run groovy again as other suggested. Or you could try to manually add it to the repository. But these are just temporary and you'll likely run into the issue again if you clear your groovy cache or with another dependency.
To troubleshoot this issue you can turn on verbose logging and try to manually install the dependency. So if your error is something like:
java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-logging#commons-logging;1.1.1!commons-logging.jar, download failed: commons-codec#commons-codec;1.6!commons-codec.jar, download failed: commons-lang#commons-lang;2.4!commons-lang.jar]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
Which means your dependency is commons-logging-1.1.1.jar. You can run:
grape -V install commons-logging commons-logging 1.1.1
What ended up solving the problem for me was overriding the default configuration and setting usepoms="false" in the localm2 resolver. It works in my case because I have the pom but not the JAR, so since Ivy isn't considering the POM now and the JAR was never there to begin with, it goes onto the next resolver which does find it. So in summary:
Create this file: ~/.groovy/grapeConfig.xml
With these contents:
<ivysettings>
<settings defaultResolver="downloadGrapes"/>
<resolvers>
<chain name="downloadGrapes" returnFirst="true">
<filesystem name="cachedGrapes">
<ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
<artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]"/>
</filesystem>
<ibiblio name="localm2" root="file:${user.home}/.m2test/repository/" checkmodified="true" changingPattern=".*" changingMatcher="regexp" m2compatible="true" usepoms="false"/>
<ibiblio name="jcenter" root="https://jcenter.bintray.com/" m2compatible="true"/>
<ibiblio name="ibiblio" m2compatible="true"/>
</chain>
</resolvers>
</ivysettings>
I was tempted not to use the maven 2 cache at all, but if I removed the line, I got errors about not being able to find "localm2". Although updating it to point to fictitious directory worked.

Deleting .m2 and grapes did not resolve the issue for me as when they were repopulated, the jar was not being downloaded. In my case, I was missing xml-apis-1.3.04.jar
I eventually resolved the issue by manually downloading the jar file and copying it into ~/.m2/repository/xml-apis/xml-apis/<version>
Hopefully this is useful if simply deleting the directories isn't working.

this might help someone down the line as i faced similar issue in windows
java.lang.RuntimeException: Error grabbing Grapes -- [download failed: commons-collections#commons-collections;3.2.2!commons-collections.jar]
the required jar above was not being downloaded in C:/Users/%USER%/.groovy/grapes/common-collections/jars/ folder.
so manually downloaded the required version from https://jar-download.com/
and added in the corresponding folder

Not quite the same case as the question, adding it in case someone finds himself in a similar case with me where I did not have any direct access on the machine to check the grapeConfig.xml configuration file, as suggested by the accepted answer. What worked for me was to configure a grab resolver.
I did something similar with what is stated in the documentation and it worked (documentation link):
#GrabResolver(name='restlet', root='http://maven.restlet.org/')
#Grab(group='org.restlet', module='org.restlet', version='1.1.6')

I solved a similar issue by using a newer version of commons-codec:commons-codec in groovy script using the #Grab annotation:
#Grapes([
#Grab('org.slf4j:slf4j-simple:1.7.25'),
#Grab('commons-codec:commons-codec:1.14'),
#Grab('io.github.http-builder-ng:http-builder-ng-apache:1.0.4')
])

you need create ~/.groovy/grapeConfig.xml
coments
<ivysettings>
<settings defaultResolver="downloadGrapes"/>
<resolvers>
<chain name="downloadGrapes" returnFirst="true">
<filesystem name="cachedGrapes">
<ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
<artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision](-[classifier]).[ext]"/>
</filesystem>
<ibiblio name="localm2" root="file:${user.home}/.m2test/repository/" checkmodified="true" changingPattern=".*" changingMatcher="regexp" m2compatible="true" usepoms="false"/>
<ibiblio name="jcenter" root="https://jcenter.bintray.com/" m2compatible="true"/>
<ibiblio name="ibiblio" m2compatible="true"/>
</chain>
</resolvers>
</ivysettings>

I had a similar error when using Groovy + Java 7.
The error from groovy was:
General error during conversion: Error grabbing Grapes -- [unresolved dependency: com.microsoft.sqlserver#mssql-jdbc;6.4.0.jre7: not found]
When trying the
grape -V resolve com.microsoft.sqlserver mssql-jdbc 6.4.0.jre7
command i had these errors:
java.net.SocketException: Connection reset
javax.net.ssl.SSLException: Received fatal alert: protocol_version
The way to fix this was adding the -Dhttps.protocols=TLSv1.2 parameter:
grape -Dhttps.protocols=TLSv1.2 -V resolve com.microsoft.sqlserver mssql-jdbc 6.4.0.jre7
Then the package is downloaded and i can use it from Groovy

Related

Quarkus native and org.kohsuke:github-api - Failed to deserialize exception

I'm playing with Quarkus native and org.kohsuke:github-api:1.111 and I see Failed to deserialize exception in native mode when doing simple new GitHubBuilder().withOAuthToken(ghToken).build();. This works in JVM mode.
The main problem is probably the fact that org.kohsuke:github-api is not ready for native mode.
I still want to ask if there are any options to workaround this, maybe some jackson tricks for https://github.com/github-api/github-api/blob/master/src/main/java/org/kohsuke/github/GHMyself.java (stacktrace contains Cannot construct instance of org.kohsuke.github.GHMyself (no Creators, like default construct, exist)).
Exception details:
2020-05-05 10:47:06,891 ERROR [io.qua.ver.htt.run.QuarkusErrorHandler] (executor-thread-1) HTTP Request to /hello failed, error id: a71018e5-de46-43a0-a194-80bd0b477f3d-1: org.jboss.resteasy.spi.UnhandledException: org.kohsuke.github.HttpException: Server returned HTTP response code: 200, message: '200 OK' for URL: https://api.github.com/user
...
Caused by: java.io.IOException: Failed to deserialize {"login":"rsvoboda","id":925259,"node_id":"MDQ6VXNlcjkyNTI1OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/925259?v=4","gravatar_id":"","url":"https://api.github.com/users/rsvoboda","html_url":"https://github.com/rsvoboda","followers_url":"https://api.github.com/users/rsvoboda/followers","following_url":"https://api.github.com/users/rsvoboda/following{/other_user}","gists_url":"https://api.github.com/users/rsvoboda/gists{/gist_id}","starred_url":"https://api.github.com/users/rsvoboda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rsvoboda/subscriptions","organizations_url":"https://api.github.com/users/rsvoboda/orgs","repos_url":"https://api.github.com/users/rsvoboda/repos","events_url":"https://api.github.com/users/rsvoboda/events{/privacy}","received_events_url":"https://api.github.com/users/rsvoboda/received_events","type":"User","site_admin":false,"name":"Rostislav Svoboda","company":"JBoss by Red Hat by IBM","blog":"https://twitter.com/r_svoboda","location":"Brno, Czech Republic","email":"rsvoboda#redhat.com","hireable":null,"bio":null,"public_repos":138,"public_gists":3,"followers":18,"following":2,"created_at":"2011-07-19T12:18:08Z","updated_at":"2020-04-29T14:38:31Z"}
at org.kohsuke.github.GitHubResponse.parseBody(GitHubResponse.java:87)
at org.kohsuke.github.GitHubClient.lambda$fetch$0(GitHubClient.java:146)
at org.kohsuke.github.GitHubClient.createResponse(GitHubClient.java:404)
at org.kohsuke.github.GitHubClient.sendRequest(GitHubClient.java:358)
... 37 more
Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `org.kohsuke.github.GHMyself` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)
at [Source: (String)"{"login":"rsvoboda","id":925259,"node_id":"MDQ6VXNlcjkyNTI1OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/925259?v=4","gravatar_id":"","url":"https://api.github.com/users/rsvoboda","html_url":"https://github.com/rsvoboda","followers_url":"https://api.github.com/users/rsvoboda/followers","following_url":"https://api.github.com/users/rsvoboda/following{/other_user}","gists_url":"https://api.github.com/users/rsvoboda/gists{/gist_id}","starred_url":"https://api.github.com/users/rsvobod"[truncated 734 chars]; line: 1, column: 2]
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1592)
at com.fasterxml.jackson.databind.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1058)
at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1297)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:159)
at com.fasterxml.jackson.databind.ObjectReader._bindAndClose(ObjectReader.java:1719)
at com.fasterxml.jackson.databind.ObjectReader.readValue(ObjectReader.java:1261)
at org.kohsuke.github.GitHubResponse.parseBody(GitHubResponse.java:84)
Reproducer details:
generate the app - https://quarkus.io/guides/getting-started#bootstrapping-the-project
add dependencies and quarkus.native.enable-https-url-handler propery for native
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.111</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
...
<properties>
<quarkus.package.type>native</quarkus.package.type>
<quarkus.native.enable-https-url-handler>true</quarkus.native.enable-https-url-handler>
</properties>
change GreetingResource
GitHub github = new GitHubBuilder().withOAuthToken(ghToken).build();
GHRepository ghRepo = github.getRepository("quarkusio/quarkus");
return ghRepo.toString();
drop .body(is("hello")) from GreetingResourceTest
run mvn clean verify -Dnative
You can also use #RegisterForReflection(targets = GHObject.class) on any of your classes
My guess is that you will need to register all the GHObject hierarchy for reflection using a ReflectiveHierarchyBuildItem.
So that requires an extension. It would be a useful addition for the Platform IMHO.
If you are running in native mode and getting the error is because of reflection to resolve the annotate your class with #RegisterForReflection also add a no-args constructor in your class then rebuild the application and run your error will be resolved.
for more reference see quarkus guide on the link

CDIIntegrationService errors were found when Weblogic upgrade from 12.1.2 to 12.1.3

I have upgraded Weblogic version in linux server by changing the wl_home path in the setDomainEnv.sh for 12.1.2 to 12.1.3 and restart. when restarting it gives below errors.
Appreciate if anyone can give idea about this.
java.lang.IllegalAccessError: tried to access method com.bea.logging.LogBufferHandler.bufferLogObject(Ljava/lang/Object;)V from class weblogic.logging.log4j.WLLog4jMemoryBufferAppender
java.lang.IllegalStateException: Unable to perform operation: post construct on weblogic.diagnostics.lifecycle.LoggingServerService
java.lang.IllegalArgumentException: While attempting to resolve the dependencies of weblogic.diagnostics.lifecycle.DiagnosticFoundationService errors were found
java.lang.IllegalStateException: Unable to perform operation: resolve on weblogic.diagnostics.lifecycle.DiagnosticFoundationService
java.lang.IllegalArgumentException: While attempting to resolve the dependencies of com.oracle.injection.integration.CDIIntegrationService errors were found
java.lang.IllegalStateException: Unable to perform operation: resolve on com.oracle.injection.integration.CDIIntegrationService
Use the wllog4j.jar which is part of WLS 12.1.3 build. The one part of WLS_HOME/server/lib diretory.
If your domains-home/lib folder holds older wllog4.jar which was part of 12.1.2 then you will face this issue

Jhipster gradle build failde

When running jhipster from command line I get the following error, I am using jhipster latest version (v3.12.2) on windows machine. It seems there is an issue with gradle build.
gradlew.bat bootRun
:cleanResources
:bootBuildInfo
:bower
:nodeSetup SKIPPED
:gulpConstantDev
[15:59:03] Using gulpfile C:\dev\test\gulpfile.js
[15:59:03] Starting 'ngconstant:dev'...
[15:59:03] Finished 'ngconstant:dev' after 23 ms
:processResources
:compileJava
:classes
:findMainClass
:pathingJar
:bootRun
java.lang.NoClassDefFoundError: org/springframework/core/env/Environment
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.springframework.core.env.Environment
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" :bootRun FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':bootRun'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_66\bin\java.exe'' finished with non-zero exit value 1
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 15.498 secs
Using Maven works.
Regards
Yes, there is a gradle issue in this version, which produces this error if gradle cache path contains spaces. I suggest you permanently remove gradle cache to a path without spaces: Set Gradle Cache Directory?
If you need a temporary quick fix, like me, you can patch this using a dirty approach to fix the JHipster classpath. Suppose your Windows user name is "Your Name". Then it will be a part of the path string and you will need to replace it with "yourna~1" (it is the 8-chars equivalent for Windows long name directories, i.e. first 6 chars of the directory name lowercase without spaces + "~1"). You can patch it in your build.gradle, line 55 and the issue is gone:
attributes 'Class-Path': configurations.runtime.files.collect {
it.toURL().toString().replaceFirst(/file:\/+/, '/').replace("Your Name", "yourna~1")
}.join(' ')

i installed maven in my locale. i was run the demositecommerce project but i get the exception

i installed maven in my locale. i was run the demositecommerce project but i get the exception
my maven paths are:
JAVA_HOME:C:\Program Files\Java\jdk1.7.0\jre
M2_HOME:C:\Program Files\apache-maven-3.3.1
PATH:C:\Program Files\Java\jdk1.7.0\bin;C:\Program Files\apache-maven-3.3.1\bin;
whenever i run the jetty-demo i get the Exception
cause Exception:
Buildfile: C:\eclipse-workspace\DemoSite\site\build.xml
start-db:
[echo] Starting Data Base...
jetty-demo:
[artifact:mvn] Listening for transport dt_socket at address: 8000
[artifact:mvn] -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
[artifact:mvn] Java Result: 1
BUILD SUCCESSFUL
Total time: 3 seconds
how can i solve this pls tell me
This seems to be a common problem with Maven 3.3 projects run from Eclipse which can be fixed by explicitly passing the maven.multiModuleProjectDirectory property to the JVM.
So in your case, to fix this error, try to edit the jetty-demo ant task in your site/build.xml file and add the following JVM argument:
<jvmarg value="-Dmaven.multiModuleProjectDirectory=$M2_HOME" />

Downloading dependencies using grape with Jenkins Job DSL plugin error

I did a job using Jenkins Job DSL plugin to get SVN branches with SVNKit libraries, but I have one problem setting de jar libraries using Grape (which uses Ivy).
If I set this in my script:
#Grapes(
#Grab(group='org.tmatesoft.svnkit', module='svnkit', version='1.8.3')
)
import org.tmatesoft.svn.core.SVNDirEntry
import org.tmatesoft.svn.core.SVNNodeKind
...
...
I get the following error:
FATAL: startup failed:
General error during conversion: Error grabbing Grapes -- [download failed: net.java.dev.jna#jna;3.5.2!jna.jar]
java.lang.RuntimeException: Error grabbing Grapes -- [download failed: net.java.dev.jna#jna;3.5.2!jna.jar]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
...
It's quite curious because if I go to %USERPROFILE%\.groovy\grapes\org.tmatesoft.svnkit\svnkit\jars the jars of SVNKIT are there but for some strange reason Grapes can't download JNA jars.
I workaround this problem downloading JNA jar in the grapes path, and it worked, but I would like what is happening and how to do this in the right way.
I'm using:
Windows 7 64 bits
Oracle JDK 1.6.0_45
Apache Tomcat 5.5.26
Jenkins 1.553
Job DSL Jenkins plugin 1.21
UPDATE:
I don't know why, but now after delete de .groovy folder, seems that is working ok.
I guess that I had a network problem while I try to get JNA for the first time and Ivy decided to set JNA as broken link on Maven Central. The reason why now works could be because after I delete the .groovy folder, Grape tried to download and this time network was ok.
It would be nice if someone can clarify this :)
We use our nexus as a host in the grapeConfig.xml.
<?xml version="1.0" encoding="UTF-8"?>
<ivy-settings>
<settings defaultResolver="downloadGrapes" />
<property name="repo.host" value="ourhost.on.network" override="false"/>
<property name="repo.realm" value="Sonatype Nexus Repository Manager" override="false"/>
<property name="repo.user" value="xxx" override="false"/>
<property name="repo.pass" value="xxx" override="false"/>
<credentials host="nexus.evdssz.admin.ch" realm="${repo.realm}" username="${repo.user}" passwd="${repo.pass}"/>
<resolvers>
<chain name="downloadGrapes" returnFirst="true">
<ibiblio name="nexus" root="https://ourhost.on.network:8443/nexus/content/groups/public/" m2compatible="true"/>
<ibiblio name="nexusreleases" root="https://ourhost.on.network:8443/nexus/content/repositories/releases/" m2compatible="true"/>
<ibiblio name="localm2" root="file:/opt/jenkins_home/.m2/repository/" checkmodified="true" changingPattern=".*" changingMatcher="regexp" m2compatible="true"/>
</chain>
</resolvers>
</ivy-settings>
The following example code is used in the groovy library in Jenkins:
import com.google.common.collect.HashBiMap
#Grab(group='com.google.code.google-collections', module='google-collect', version='snapshot-20080530')
def getFruit() { [grape:'purple', lemon:'yellow', orange:'orange'] as HashBiMap }
assert fruit.lemon == 'yellow'
assert fruit.inverse().yellow == 'lemon'
Enable debugging on what grape is doing. Install the grape tool on your Jenkins.
Set the java options to enable debugging information:
JAVA_OPTS="-Dgroovy.grape.report.downloads=true -Divy.message.logger.level=4 "
The info above comes from here:
http://docs.groovy-lang.org/latest/html/documentation/grape.html
After all new configuration I also:
- deleted .groovy/grapes/*
- restarted jenkins
Mike
Have you tried to configure a grab resolver (http://docs.groovy-lang.org/latest/html/api/groovy/lang/GrabResolver.html) ? I don't know the default resolver for grape, but maybe the default resolver does no work.
I think sometimes when dependencies are being resolved with Grapes (and perhaps other similar technologies), some flag is toggled before the dependency gets fully downloaded or configured properly. I have had this happen with Maven and Gradle as well and the problem is usually resolved by blowing away cached artifacts in .m2 or .gradle and force them to be fetched again.

Resources