Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ bin/
data.json
demo/libs/*.jar
derive.rb
gradlew.bat
switch_java.sh
.DS_Store
.vscode/
8 changes: 7 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
The main library JAR is under build/libs/ (`serpapi-<version>.jar`, where `<version>` 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.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ dependencies {
}
```

With Maven, add these lines to your `pom.xml`:

```xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.github.serpapi</groupId>
<artifactId>serpapi-java</artifactId>
<version>1.2.0</version>
</dependency>
</dependencies>
```

To list all available versions see:
https://jitpack.io/api/builds/com.github.serpapi/serpapi-java

Expand Down
26 changes: 25 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jacocoTestReport {
base {
archivesName = 'serpapi'
}
version = '1.2.0'
// version is set in gradle.properties
group = 'com.github.serpapi'

java {
Expand Down Expand Up @@ -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 =~ /<artifactId>serpapi-java<\/artifactId>\s*<version>([^<]+)<\/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 }
7 changes: 6 additions & 1 deletion demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
Binary file added demo/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions demo/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions demo/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 93 additions & 0 deletions demo/gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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
93 changes: 93 additions & 0 deletions gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading