diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 95f5b44..5013385 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -25,6 +25,8 @@ jobs: run: chmod +x gradlew - name: Build with Gradle uses: gradle/actions/setup-gradle@v3 + - name: check version references + run: ./gradlew checkVersionReferences - name: test run: ./gradlew test env: diff --git a/.gitignore b/.gitignore index 974c7b2..7dc1104 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,6 @@ bin/ data.json demo/libs/*.jar derive.rb -gradlew.bat switch_java.sh .DS_Store .vscode/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 452a89a..09c4588 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,4 +41,10 @@ Build (use the wrapper): ./gradlew build ``` -The main library JAR is under build/libs/ (for example serpapi-1.1.0.jar, name follows version in build.gradle). Copy it into your project’s lib/ directory if you are not using Maven/Gradle dependency resolution. \ No newline at end of file +The main library JAR is under build/libs/ (`serpapi-.jar`, where `` is the `version` in gradle.properties). Copy it into your project’s lib/ directory if you are not using Maven/Gradle dependency resolution. + +## Releasing + +The library version lives only in `gradle.properties` (`version=…`); `build.gradle` and `demo/build.gradle` read it from there. +To release, change it there, then update every install snippet in `README.md` (Gradle, Maven and the migration example). +`./gradlew checkVersionReferences` (run in CI and by `make release`) fails if any snippet still names another version. diff --git a/Makefile b/Makefile index b2b5445..f02a7bc 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ doc: # Create a release using GitHub release: doc build + ./gradlew checkVersionReferences @echo "drag drop file" open build/libs/ open build/distributions/ diff --git a/README.md b/README.md index 4c732f0..7246db5 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,25 @@ dependencies { } ``` +With Maven, add these lines to your `pom.xml`: + +```xml + + + jitpack.io + https://jitpack.io + + + + + + com.github.serpapi + serpapi-java + 1.2.0 + + +``` + To list all available versions see: https://jitpack.io/api/builds/com.github.serpapi/serpapi-java diff --git a/build.gradle b/build.gradle index 4f996dd..aba006f 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ jacocoTestReport { base { archivesName = 'serpapi' } -version = '1.2.0' +// version is set in gradle.properties group = 'com.github.serpapi' java { @@ -91,3 +91,27 @@ wrapper { gradleVersion = "9.1.0" distributionType = Wrapper.DistributionType.ALL } + +// Fail when an install snippet in README.md names a version other than gradle.properties. +def checkVersionReferences = tasks.register('checkVersionReferences') { + group = 'verification' + description = 'Checks that README.md install snippets use the version in gradle.properties.' + def readme = layout.projectDirectory.file('README.md') + def expected = project.version.toString() + inputs.file(readme) + inputs.property('version', expected) + doLast { + def text = readme.asFile.text + def found = [] + (text =~ /com\.github\.serpapi:serpapi-java:([\w.\-]+)/).each { found << it[1] } + (text =~ /serpapi-java<\/artifactId>\s*([^<]+)<\/version>/).each { found << it[1] } + if (found.isEmpty()) { + throw new GradleException("README.md: no serpapi-java install snippet found") + } + def stale = found.findAll { it != expected } + if (!stale.isEmpty()) { + throw new GradleException("README.md install snippets use ${stale.unique()} but gradle.properties has version=${expected}") + } + } +} +tasks.named('check') { dependsOn checkVersionReferences } diff --git a/demo/build.gradle b/demo/build.gradle index f718741..c922e1b 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -26,12 +26,17 @@ repositories { maven { url "https://jitpack.io" } } +// The demo uses the library version from the root gradle.properties, so it can't go stale. +def serpapiProps = new Properties() +file('../gradle.properties').withInputStream { serpapiProps.load(it) } +def serpapiVersion = serpapiProps.getProperty('version') + dependencies { def localJars = fileTree(dir: 'libs', include: '*.jar') if (!localJars.isEmpty()) { implementation localJars } else { - implementation 'com.github.serpapi:serpapi-java:1.0.0' + implementation "com.github.serpapi:serpapi-java:${serpapiVersion}" } implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.5' } diff --git a/demo/gradle/wrapper/gradle-wrapper.jar b/demo/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..8bdaf60 Binary files /dev/null and b/demo/gradle/wrapper/gradle-wrapper.jar differ diff --git a/demo/gradle/wrapper/gradle-wrapper.properties b/demo/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..a35649f --- /dev/null +++ b/demo/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-all.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/demo/gradlew b/demo/gradlew index 249efbb..adff685 100755 --- a/demo/gradlew +++ b/demo/gradlew @@ -20,7 +20,7 @@ ############################################################################## # -# gradlew start up script for POSIX generated by Gradle. +# Gradle start up script for POSIX generated by Gradle. # # Important for running: # @@ -29,7 +29,7 @@ # bash, then to run this script, type that shell name before the whole # command line, like: # -# ksh gradlew +# ksh Gradle # # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: @@ -57,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. diff --git a/demo/gradlew.bat b/demo/gradlew.bat new file mode 100644 index 0000000..e509b2d --- /dev/null +++ b/demo/gradlew.bat @@ -0,0 +1,93 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..b95d6f1 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,3 @@ +# Library version: the single source of truth. +# demo/build.gradle reads it, and `./gradlew checkVersionReferences` checks README.md against it. +version=1.2.0 diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..e509b2d --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,93 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega