google-search-results-java icon indicating copy to clipboard operation
google-search-results-java copied to clipboard

Cant get this artifact from jitpack

Open ai-for-java opened this issue 1 year ago • 4 comments

Hello,

How do I get this library in maven? Could you please help?

This is what I have in my pom.xml: <dependency> <groupId>com.github.serpapi</groupId> <artifactId>google-search-results-java</artifactId> <version>2.0.3</version> </dependency>

and: <repositories> <repository> <id>jitpack.io</id> <url>https://www.jitpack.io</url> </repository> </repositories>

But I am always getting this error: [ERROR] Failed to execute goal on project xxx: Could not resolve dependencies for project xxx: The following artifacts could not be resolved: com.github.serpapi:google-search-results-java:jar:2.0.3 (absent): Could not find artifact com.github.serpapi:google-search-results-java:jar:2.0.3 in jitpack.io (https://www.jitpack.io)

Thank you!

ai-for-java avatar May 17 '23 20:05 ai-for-java

I have encountered the same issue and hope it can be resolved. Thank you.

HamaWhiteGG avatar Jun 13 '23 03:06 HamaWhiteGG

Any update on this? I am also experiencing this issue.

steelcityamir avatar Jun 30 '23 21:06 steelcityamir

@codebyamir Temporary Solution, I copied this code into my project langchain-java and pushed it to the Maven repository. https://github.com/HamaWhiteGG/langchain-java

You can use the following Maven dependency:

<!-- https://mvnrepository.com/artifact/io.github.hamawhitegg/serpapi-client -->
<dependency>
    <groupId>io.github.hamawhitegg</groupId>
    <artifactId>serpapi-client</artifactId>
    <version>0.1.7</version>
</dependency>

Note that it requires Java 17 or later(Because my entire project is using Java 17.).

Here is an example code:

SerpApiSearch search = new GoogleSearch();

Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "google");
parameter.put("google_domain", "google.com");
parameter.put("gl", "us");
parameter.put("hl", "en");
parameter.put("q", "High temperature in SF yesterday");

search.setParameter(parameter);

JsonObject result = search.getJson();
String searchResult = result.getAsJsonArray("organic_results")
  .get(0)
  .getAsJsonObject()
  .get("snippet")
  .getAsString();

System.out.println(searchResult);

The output is like:

See weather overview. San Francisco Temperature Yesterday. Maximum temperature yesterday: 69 °F (at 2:56 pm) Minimum temperature yesterday: 54 °F (at 4:56 am)

HamaWhiteGG avatar Jul 01 '23 01:07 HamaWhiteGG

@jvmvik, may https://github.com/serpapi/google-search-results-java/pull/3 fix the artifacts downloading?

Edit:

@ai-for-java @codebyamir @HamaWhiteGG Follow the next steps to get artifacts from the jitpack:

  1. Add repository
<repositories>
  <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
  </repository>
</repositories>
  1. Add classifier to the dependency. (The package name contains the suffix: google-search-results-java-2.0.3-sources.jar.)
<dependency>
      <groupId>com.github.serpapi</groupId>
      <artifactId>google-search-results-java</artifactId>
      <version>2.0.3</version>
      <classifier>sources</classifier>
  </dependency>
  1. Compile the project following the Maven's magic
mvn clean install dependency:copy-dependencies package && javac -classpath .:target/dependency/* -d . $(find . -type f -name '*.java')`
  1. Run the code
java -cp .:target/dependency/* Main

Full example:

  • Code: https://replit.com/@ilyazub/serpapi-google-search-results-java-maven#Main.java
  • pom.xml: https://replit.com/@ilyazub/serpapi-google-search-results-java-maven#pom.xml
  • Compilation and execution scripts: https://replit.com/@ilyazub/serpapi-google-search-results-java-maven#.replit

ilyazub avatar Nov 14 '23 20:11 ilyazub