Using particular clojure java-wrapper with no project.clj - java

I try to avoid asking questions that won't help many other people, but I've been at this for far too long to not ask for help. I'm trying to use this clojure wrapper for a java package as a dependency in my project, but I'm hitting a lot of errors because there's no project.clj.
I've tried using the lein-git-deps plugin with the following keys in my project.clj:
:plugins [[lein-git-deps "0.0.1-SNAPSHOT"]]
:git-dependencies [["https://github.com/lunkdjedi/clj-ta-lib"]]
Running $ lein git-deps gives me the following:
Setting up dependency for [https://github.com/lunkdjedi/clj-ta-lib]
Running git pull on .lein-git-deps
Running git checkout master in .lein-git-deps
but nothing changes in my local directory, except now there's an empty .lein-git-deps/ dir. I'm assuming this didn't work because of the missing project.clj.
I've been able to clone the project and call $ mvn package clojure:repl which successfully compiled and opened a REPL instance, in which I could use the wrapper perfectly. When I run $ lein install it gives me:
Couldn't find project.clj, which is needed for install
but when I run $ mvn install it gives me a BUILD SUCCESS and can be found in ~/.m2/repositories/clj-ta-lib.
I put :dependencies [[clj-ta-lib/clj-ta-lib "0.0.1"]] in my project.clj and restart the REPL but when I call (use 'clj-ta-lib.core) I get:
CompilerException java.lang.Exception: namespace 'clj-ta-lib.core' not found, compiling:(*cider-repl app*:71:13)
Edit:
No longer getting the previous error, but still getting this one:
CompilerException java.lang.IllegalArgumentException: No matching ctor found for class com.tictactec.ta.lib.meta.PriceHolder, compiling:(clj_ta_lib/core.clj:13:3)

The stuff you say you've done sounds pretty reasonable. It's a shame the project isn't hosted on clojars or on maven central, but at least there's a pom to allow you to publish or install it easily yourself. mvn install is the right thing to do, and when I clone the project myself and install it, everything installs fine just as you say it does.
However, I can't reproduce your error when trying to use the library. After installing it, I created a new project that depends on the just-installed artifact, and in a repl inside that project, I can use the library's classes just fine. Or, well, I don't know how to use these functions as intended, but the functions are available for my use:
user=> (use 'clj-ta-lib.core)
nil
user=> ta
#<core$ta clj_ta_lib.core$ta#c668834>
So I'd say, make sure you really did follow all the steps you say you did, and that your repl has been started cleanly inside of the project that depends on your library.

As mentioned here, https://mvnrepository.com/artifact/com.tictactec/ta-lib/0.4.0 just add [com.tictactec/ta-lib "0.4.0"] to the dependencies
in your project.clj.
:dependencies [[com.tictactec/ta-lib "0.4.0"]]

Related

Is it possible to package a portable maven in the project (and some general direction on how)?

The solution which needs bootstrapping is supplied as java code. Absolutely sure that this is necessary.
Receivers of the solution are guaranteed to have a suitable JDK
However, receivers of the solution are unable to install Maven (they don't know how to and cannot be taught)
My idea is to include some sort of Maven with the project, such that can be set up in a script like so:
set up maven repo as a folder under the solution folder (using relative reference)
set up anything else maven needs (don't know what, exactly)
call /path/to/maven/mvn compile -f /path/to/oneAndOnly/pom.xml
java /target/MySolutionClas
I am aware of: https://dzone.com/articles/embedding-maven but it gets confusing when he talks about configuring the portable maven into the pom.xml - wait, how is that pom.xml going to mean anything if maven is not configured yet?
(PS: I mean no disrespect to the author. I probably got it all wrong)
One could include a shell script that would setup maven if it is not already present.
The same for building and packaging encapsulating the complexities of the setup to just runing a couple of scripts.
Maven Wrapper aims to do just that, similar to the gradle wrapper seen in many gradle projects.
Running the wrapper goal of the maven wrapper plugin will generate a mvnw script in your project that can be run in place of a globally installed mvn command.
It's part of the maven 3.7.0 release, and documented more fully here: https://maven.apache.org/plugins/maven-wrapper-plugin/index.html
See https://github.com/takari/maven-wrapper for maven < 3.7.0

"Cannot find declaration to go" protos declaration in IntelliJ IDEA

I am trying to use gRPC proto file to generate stub code for inter-service communication. Everything is okay and when I run mvn clean install, it installs everything and builds successfully.
But still now protos files are in red color and can’t go definition when I click to go to it’s definition. It says me Cannot find declaration to go. When build is successful then why it is not possible to find declaration in IntelliJ IDEA?
I clean every cached on IDE and indexing is also successful. I also cleared m2 cache.
Is there anything to find this solution so that I can go to proto class definition?
Any help will be appreciated.
Thanks.
Your IntelliJ IDEA  needs to generate Project setup. So you need to execute the main plugin goal, which is idea:idea.
Use this command. It will helped me.
mvn -U idea:idea
Here
-U = Forces a check for missing releases and updated snapshots on remote repositories

How do I know which project is requesting a specific jar from Maven

I'm using Eclipse and recently upgraded all my projects to use the latest version of a library.
However in the Maven repository I can still see the old version of the library.
I've deleted manually the old library from the Maven repository, but it keeps coming back.
I am sure all the projects in Eclipse point to the new version: I've checked all my pom.xml, I've used the "Dependency Hierarchy" tool, etc.
Is there a way to know which project is telling Maven to download the old version of the library?
Many thanks!
You can use the Maven dependency plugin's tree goal:
mvn dependency:tree
and filter using the includes option which uses the pattern [groupId]:[artifactId]:[type]:[version].
Re: "and I have many". Perform the following in the topmost directory:
find . -name "pom.xml" -type f -exec mvn dependency:tree -f {} ';' | grep '^\[.*\] [-+\\\|].*'
Syntax details may vary from Bash to Bash.
Hint: Try it in a bottommost project directory first to ensure that it runs properly as intended. Since you have many projects it may take a while to finish and to recognize possible errors only then.
You can use below command to get a tree of all dependencies and then find out where the specific artifact is coming from.
You can pipe with grep to show only the related ones if you you are on linux/unix based os.
mvn dependency:tree
Thanks guys, appreciated, but it certainly is not an easy way. It looks like you have to do project by project (and I have many). Plus most of my pom reference poms in other folders and it's not able to process that either.

Which class is Maven calling?

I am looking at an internal Maven application I am building in IntelliJ (same results in Eclipse), and everything looks perfectly clean.
I run clean and compile from IntelliJ (using IntelliJ build or using IntelliJ Maven support) and everything compiles fine.
However when I run the build from the command line (mvn clean compile) I am getting build exceptions (see below).
The command line seems to be looking for a genericized parameter (to the "with" method), which we are indeed passing in correctly. However it is complaining as if we were passing in a non-generic parameter.
Obviously mvn on the command line is using a different version of the "with" method than IntelliJ.
Is there any way to ask Maven to tell me which version of a class it is using, in terms of group, artifact and version of the containing jar?
Here is the precise error
[ERROR] \dev\try-deploy-1\src\main\java\com\victor\webui\WebUserInterface.java:[147,47]
attribute(java.lang.String,org.hamcrest.Matcher<java.lang.String>) in
org.openqa.selenium.lift.Matchers cannot be applied to
(java.lang.String,org.hamcrest.Matcher<java.lang.Object>)
Is it possible that you have another version of the class somewhere? try adding a comment on a new line in the file so the line number changes, and re-run the maven compile to see if it still gives the same line number for the error.
In Eclipse, sorry I know you are using IntelliJ, the maven build usually does an offline build that's why it's so fast. There is a way to force it to do a clean with all the jars though and I use that when I get in a bind. It is the Update Project command and it has a box to force the update of snapshots and releases. Maybe Intellij has something like that? Also I'd verify the version you are using on command line is the same as the one IntelliJ is using (I have a few versions installed). You can check Settings in IntelliJ and
mvn -v
on the command line. Finally I'd make sure the settings.xml files you are using for command line and IntelliJ are the same file.
Good luck.

Why do my tests fail to run when migrating from maven2 to buildr?

I have a straightforward maven2 java project (JMS relaying system). After we released the first version, we found that we spent more time configuring maven than actually coding.
For the next release we wanted to clean up the build process and someone suggested migrating to builder. So I was tasked with doing just that.
I setup buildr (1.3.4) according to the documentation on their website. And then from the root of the project I typed the buildr command and then informed buildr to create the build file based upon my pom.xml. That processed fine and compiled all the code. All was gravy until buildr started running the tests. Here is the ouput:
Test framework error: taskdef class org.apache.tools.ant.taskdefs.optional.junit.JUnitTask cannot be found
Obviously the class specified isn't in my classpath. However, the buildr documentation says that all the required items needed for basic testing are included. Their documentation doesn't say that they need any specific libraries for ant or a version of ant. Although I do have ant 1.7.0 installed (not included in my classpath however).
Has anyone seen this before?
Update
I located the infamous ant-optional jar on the maven repository. Including that in my test.with options did not resolve the issue.
Running the buildr command with --trace gives this extra information...
Tests failed!
/pathtoruby/buildr-1.3.4/lib/buildr/core/test.rb:455:in `run_tests'
/pathtoruby/buildr-1.3.4/lib/buildr/core/test.rb:199:in `initialize'
Found the issue... Apparently there is an ant-junit.jar that is needed but for whatever reason in my local repository it was owned by root and not my local user account (OSX system). So it wasn't accessible to buildr. I deleted the items from my local repository and reran buildr (it downloaded the needed items).
Update
Also this caused a few other issues. It seems that a few other items in my local repository had strange permissions. I ended up just archiving my repository and letting maven reconstruct it. This resolved all my issues. I now have a nice build file that is 25 lines of code compared to my previous pom.xml file that was over 100 lines.
You get that error because JUnitTask isn't on the classpath. I'm not very familiar with Buildr so can't say if it is required for you to specify the JUnit jars or not, but if Buildr uses the system classpath, try adding JUnit to it and see what happens.
Once you've confirmed your builds will run with JUnit hacked in to the classpath, you can then try varying your configuration until it runs as you expected, or leave it as is.
Can you post the reference to the relevant part of the documentation? I didn't see anything (in my very brief reading of the site) that says required items are included.
Is it possible that you've not downloaded all the gems? If you run "gem update --system" to update Ruby, then "gem update buildr" you can ensure that the required dependencies have all been installed.

Categories