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

Error package serpapi does not exist

Open hilmanski opened this issue 2 years ago • 6 comments

I tried to clone this repo and run the demo

git clone https://github.com/serpapi/google_search_results_java.git
cd google_search_results_java/demo
make run api_key=<your private key>

Upon running the make run, It shows

/bin/sh: ./gradlew: No such file or directory

So I run

gradle wrapper
chmod +x gradlew

Then try to run the program either with

make run api_key=...
// or
gradle guild

It shows this error CleanShot 2023-12-06 at 16 14 45@2x

A similar thing happened when I tried to install/run the project with gradle from scratch.

Computer Info: Mac OS Sonoma 14.0

openjdk 11.0.12 2021-07-20 OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840) OpenJDK 64-Bit Server VM (build 11.0.12+0-b1504.28-7817840, mixed mode)

gradle --version


Gradle 6.7

Build time: 2020-10-14 16:13:12 UTC Revision: 312ba9e0f4f8a02d01854d1ed743b79ed996dfd3

Kotlin: 1.3.72 Groovy: 2.5.12 Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020 JVM: 11.0.12 (JetBrains s.r.o. 11.0.12+0-b1504.28-7817840) OS: Mac OS X 14.0 aarch64

hilmanski avatar Dec 06 '23 08:12 hilmanski

Try running just plain make (or the all target) first.

My build fails at the end with

BUILD SUCCESSFUL in 3s
9 actionable tasks: 9 executed
see build/lib
gmake[1]: Leaving directory '/home/freaky/code/serpapi/google_search_results_java'
rm -rf libs/*.jar
cp ../build/libs/* libs
cp: libs is not a directory
gmake: *** [Makefile:21: dep] Error 1

There's no libs directory - it was presumably an empty directory, which git doesn't track. Creating it got me as far as it attempting to compile the demo after building deps but failing to find the serpapi package.

Freaky avatar Dec 06 '23 11:12 Freaky

Uncommenting implementation fileTree(dir: "./libs", includes: ['*.jar']) in gradle.build made the demo build.

Freaky avatar Dec 06 '23 11:12 Freaky

Some deprecation warnings from gradle 8.2.1:

The RepositoryHandler.jcenter() method has been deprecated. This is scheduled to be removed in Gradle 9.0. JFrog announced JCenter's sunset in February 2021. Use mavenCentral() instead. Consult the upgrading guide for further information: https://docs.gradle.org/8.2.1/userguide/upgrading_version_6.html#jcenter_deprecation
        at build_809kfkapz59re88mheul3fxuu$_run_closure1.doCall(/home/freaky/code/serpapi/google_search_results_java/demo/build.gradle:20)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)
        at build_809kfkapz59re88mheul3fxuu.run(/home/freaky/code/serpapi/google_search_results_java/demo/build.gradle:17)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)
Build file '/home/freaky/code/serpapi/google_search_results_java/demo/build.gradle': line 32
The org.gradle.api.plugins.ApplicationPluginConvention type has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/8.2.1/userguide/upgrading_version_8.html#application_convention_deprecation
        at build_809kfkapz59re88mheul3fxuu.run(/home/freaky/code/serpapi/google_search_results_java/demo/build.gradle:32)
        (Run with --stacktrace to get the full stack trace of this deprecation warning.)
Build file '/home/freaky/code/serpapi/google_search_results_java/demo/build.gradle': line 32
The org.gradle.api.plugins.Convention type has been deprecated. This is scheduled to be removed in Gradle 9.0. Consult the upgrading guide for further information: https://docs.gradle.org/8.2.1/userguide/upgrading_version_8.html#deprecated_access_to_conventions
        at build_809kfkapz59re88mheul3fxuu.run(/home/freaky/code/serpapi/google_search_results_java/demo/build.gradle:32)

Freaky avatar Dec 06 '23 11:12 Freaky

It worked using Maven: https://github.com/serpapi/google-search-results-java/issues/22#issuecomment-1811212022. There's a related PR which I didn't check: https://github.com/serpapi/google-search-results-java/pull/3/

ilyazub avatar Dec 06 '23 18:12 ilyazub

Made it work when compiling from sources. Here's a patch:

diff --git a/build.gradle b/build.gradle
index 78b13f3..67b24c9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -48,12 +48,14 @@ tasks.named('jar') {
 }
 
 task sourcesJar(type: Jar, dependsOn: classes) {
-    classifier = 'sources'
+    archiveClassifier = 'sources'
     from sourceSets.main.allSource
+    jar.reproducibleFileOrder = true
+    jar.preserveFileTimestamps = false
 }
 
 task javadocJar(type: Jar, dependsOn: javadoc) {
-    classifier = 'javadoc'
+    archiveClassifier = 'javadoc'
     from javadoc.destinationDir
 }
 
@@ -66,6 +68,8 @@ artifacts {
 publishing {
     publications {
         mavenJava(MavenPublication) {
+	    from components.java
+
             pom {
                 licenses {
                     license {
diff --git a/demo/build.gradle b/demo/build.gradle
index 7a956ef..d994ad8 100644
--- a/demo/build.gradle
+++ b/demo/build.gradle
@@ -17,15 +17,15 @@ plugins {
 repositories {
     // Use jcenter for resolving your dependencies.
     // You can declare any Maven/Ivy/file repository here.
-    jcenter()
+    mavenCentral()
 
     maven { url "https://jitpack.io" }
 }
 
 dependencies {
-    // implementation fileTree(dir: "./libs", includes: ['*.jar'])
+    implementation fileTree(dir: "./libs", includes: ['*.jar'])
     implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5'
-    implementation 'com.github.serpapi:google-search-results-java:2.0.3'
+    // implementation 'com.github.serpapi:google-search-results-java:2.0.3'
 }
 
 // Define the main class for the application

To check how it worked:

[google-search-results-java] $ make API_KEY=<your_test_api_key>
[google-search-results-java/demo] $ make run API_KEY=<your_test_api_key>

ilyazub avatar Dec 06 '23 19:12 ilyazub

Thank you @ilyazub @Freaky for sharing your findings. I'll try again later.

It may be due to my lack of understanding of Java. But I hope the readme file can be updated with a step-by-step process on how to install it:

  • With Maven
  • With Gradle

*separately. So customers can easily work with this as well.

hilmanski avatar Dec 06 '23 22:12 hilmanski