Groovy install HTTPBuilder now that Codehaus shutdown? - maven

I'm a groovy n00b and trying to use http-builder, but ALL of the examples on the web just reference the same #Grab statement which doesn't work. I assume it is because codehaus.org isn't hosting groovy stuff anymore. I've tried downloading the source from github and building it with Maven, but the build fails.
How and where am I supposed to get httpbuilder for groovy?
Things I've already tried:
Deleting the grapes directory from this post didn't work.
I got this code snippet from this other post, but it doesn't work for me either.
#Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
def http = new groovyx.net.http.HTTPBuilder('http://www.codehaus.org')
println http
Here is the error in the IntelliJ console:
/Users/kenny/Sites/inadaydevelopment.com/reports/fetch_windows_appstore_report.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during conversion: Error grabbing Grapes --
[download failed: xerces#xercesImpl;2.9.1!xercesImpl.jar,
download failed: xml-apis#xml-apis;1.3.04!xml-apis.jar]
EDIT 1:
Tried running it from the command line, still same error message.
Tried grab artifacts in IntelliJ, but that failed too:
I wondered if it was Mac related, and bingo. I uploaded this script to my CentOS server and it ran just fine. There is something related to MacOSX+groovy that is causing the problem.

Got it! It looks like it was the maven cache that was the problem.
I found the solution on this page:
rm -rf ~/.m2/repository ~/.groovy/grapes
I had previously tried removing the ~/.groovy/grapes cache, but that didn't fix the problem. Removing the ~/.m2/repository is what actually did it for me.

This works fine from the groovy console and from the command line.
The http-builder project is hosted on Maven Central.
Grab will actually use JCenter, but JCenter mirrors Maven Central so this resolution works.
Not sure why you would have trouble resolving transitive dependencies... it may be that you are using a proxy, for example... could also be your settings for Maven or Ivy... Check the Groovy Grapes documentation to see if you might inadvertently have something configured that causes this problem.
Also, try from groovyConsole or the command-line to rule out some conflicts within IntelliJ.
From IntelliJ, point to the Grab annotation and hit Alt+Enter. Then select grab artifacts and Enter.
It should work (works for me) and you should be able to run the script without problems.
If it complains about Ivy not being in the classpath, just add Ivy to the module dependencies and it will work.

Related

Gradle could not resolve org.springframework.vault:spring-vault-core

I have a project that adopts Spring Vault to fetch credential. Dependencies of the project are as following and build.gradle file is generated automatically afterwards.
When I build the project I got the error
Could not resolve
org.springframework.vault:spring-vault-core:2.2.2.RELEASE.
Possible solution:
Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
I have checked the libraries by going to the Project Structures and got the weird thing
The weird thing I mean here is about the path of the jar file. It should be something like
%GRADLE_HOME%\caches\modules-2\files-2.1\org.springframework.cloud\spring-cloud-vault-config\2.2.3.RELEASE\5fd5a06deb01db77eb3e9b8e723ccc1e0790c420
How can I fix this issue in IntelliJ?
When you get an error about could not resolve dependencies in gradle, then there are several things you need to check.
Proxy settings (should be inside gradle.properties)
Permission for creating directories (particularly in %GRADLE_HOME%\caches\modules-2\files-2.1)
For the problem of proxy setting, simply set values for the following fields inside gradle.properties
systemProp.http.proxyHost=
systemProp.http.proxyPort=
systemProp.http.nonProxyHosts=
systemProp.https.proxyHost=
systemProp.https.proxyPort=
systemProp.https.nonProxyHosts=
For the problem of permission, try creating directories with the name of dependencies cannot be resolved, for example, org.springframework.vault at %GRADLE_HOME%\caches\modules-2\files-2.1. If you got permission denied or simply cannot create, then please contact your IT support!

Eclipse JDT LS & Gradle - Resource Exception "Invalid project description"

Summary
I've been trying to get Eclipse's JDT LS (JLS) working with vim-lsp (in Neovim), but have been unsuccessful in synchronising the JLS with a Gradle project. I am, unfortunately, constrained to Windows.
The Problem
Using this configuration (commit #d1c7a25 at the time of posting), I cannot synchronise the JLS with a Gradle project "due to an error configuring Eclipse" because of an "invalid project description" (see log).
Trawling through Google and the GitHub issues of both the JLS and vim-lsp plugin has gotten me nowhere.
Remarks
I feel like it's most likely an issue with my configuration. If anyone has got this working with other LSP plugins aside from YouCompleteMe (such as CoC or LanguageClient) those setups are also welcome, but vim-lsp is preferred.
To reiterate, and just in case:
Windows 10 Pro (v1803 build 17134.407)
Neovim (v0.3.1) with plugin vim-lsp
Gradle wrapper (v4.10.2)
Eclipse JDT LS (v0.28.0 build 201811140630) [.tar.gz]
using this configuration (originally #d1c7a25)
Thanks!
Figured it out.
The workspace directory for the JLS (specified by the command line argument -data) can't be nested under the project's own directory.
*bashes head on desk*

Maven - peer not authenticated

A few days ago my maven stopped working. To be more specific it stops download dependencies. Below I note bunch of information and steps which I did in order to find solution.
I double checked settings.xml - this file is used also by my colleagues and they haven't any problems
I installed Maven 3.0.4, 3.0.5, 3.1.0 - it always fail during download dependencies
I have 3 computers - 2 with Ubuntu and 1 with Windows. On Windows it works great, on both Ubuntu it doesn't.
mvn clean install generates in debug mode something like that: Could not transfer artifact junit:junit:pom:3.8.1 from/to central...: peer not authenticated stacktrace
I tried to use additional parameters mvn -Dmaven.wagon.http.ssl.insecure=true -Dmaven.wagon.http.ssl.allowall=true clean install
but it fails also. Output in debug mode ends with: Server key: Could not create EC public key: CKR_DOMAIN_PARAMS_INVALID
If I add all dependencies manually (copy&paste from my colleagues ~/.m2 directory) then mvn clean install works correctly. So, it seems to be a problem only with downloading.
Does anyone have any suggestions what can be wrong?
I found a solution for my problem. Be sure you have rights to write into {jdk_directory}/security/java.security file (in my case /etc/java-7-openjdk/security/java.security) and if so, then modify it this way:
from:
#security.provider.9=sun.security.ec.SunEC
security.provider.9=sun.security.pkcs11.SunPKCS11 ${java.home}/lib/security/nss.cfg
to
security.provider.9=sun.security.ec.SunEC
#security.provider.9=sun.security.pkcs11.SunPKCS11 ${java.home}/lib/security/nss.cfg
It fixed problem on all my computers (all with maven 3.0.4)

Tell gradle to bypass dependency checks

I am at a clients site, behind a firewall. Im trying to compile but gradle keeps trying to check my dependencies. The corporate firewall explicitly blocks maven downloads so my build is failing. Now I have compiled before, so the dependencies do already exist in my [user]/.gradle folder, but its been more than 24 hours so gradle is trying to do its daily "lets check the repo and make sure nothing changed stuff."
Is there a command switch or anything that im just simply not seeing here to tell gradle to bypass this version check and simply compile the code? I would even be happy with a command switch that says I don't care if dependency resolution failed, compile anyways.
Try the --offline command line switch.
You still have to get it to compile once to grab the dependencies online, so --offline only works once you have compiled successfully one time.
The only way I was able to get this to work was to tether my phone to my machine and connect to my cellular service for internet instead. That way, I bypassed my company's proxy and firewall and was able to download the dependencies once.
After that, I was able to then compile when connected to the corporate network instead. Just don't clean your project or else you'll be back where you are right now.
I found this question because I wanted to short-circuit the Maven dependency checks in a git pre-commit hook that runs gradle check for better performance. I ended up doing:
if ! ( gradle --offline check || gradle check ); then
exit 1
fi
which tries once with --offline, and then tries again without --offline if the first try fails.

how to force maven to update local repo

I compiled a jar file in one project so it can be consumed in the 2nd one. I can see the jar file in .m2 folder. But in the 2nd project it complains about artifact not found.
I guess I have to force maven to update indices/cache something but don't know what exactly. Any tip, thanks.
Update: thanks for all good suggestions.
Turns out that the maven plugin (of IntelliJ) in the second project doesn't update its index. I use command line it compiled ok.
try using -U (aka --update-snapshots) when you run maven
And make sure the dependency definition is correct
You can also use this command on the command line:
mvn dependency:purge-local-repository clean install
If you are installing into local repository, there is no special index/cache update needed.
Make sure that:
You have installed the first artifact in your local repository properly. Simply copying the file to .m2 may not work as expected. Make sure you install it by mvn install
The dependency in 2nd project is setup correctly. Check on any typo in groupId/artifactId/version, or unmatched artifact type/classifier.
Even though this is an old question, I 've stumbled upon this issue multiple times and until now never figured out how to fix it. The update maven indices is a term coined by IntelliJ, and if it still doesn't work after you've compiled the first project, chances are that you are using 2 different maven installations.
Press CTRL+Shift+A to open up the Actions menu. Type Maven and go to Maven Settings. Check the Home Directory to use the same maven as you use via the command line
Click settings and search for "Repositories", then select the local repo and click "Update". That's all. This action meets my need.
If you are struggling with authenticating to a site, and Maven is caching the results, simply removing the meta-data about the site from the meta-data stash will force Maven to revisit the site.
gvim <local-git-repository>/commons-codec/resolver-status.properties

Resources