The recommended method for obtaining the SDK is via Gradle or Maven through the Maven Central repository. Direct download links are also provided below.
compile "com.smartcar.sdk:java-sdk:4.8.1"<dependency>
<groupId>com.smartcar.sdk</groupId>
<artifactId>java-sdk</artifactId>
<version>4.8.1</version>
</dependency>Signatures and other downloads available at Maven Central.
For authentication, Smartcar uses the authorization code request flow of the OAuth 2.0 specification. Before you can make successful calls to the Smartcar platform, you will need to authenticate with Smartcar, and then obtain a valid access token for the target vehicle.
-
Make sure you have your application set up in the Smartcar Developer Dashboard. You will need the following 3 pieces of information associated with your application:
- Client ID
- Client Secret
- Redirect URI
-
You can then generate an authentication URL for your user:
// Setup String clientId = ""; String clientSecret = ""; String mode = "test"; // Initialize a new AuthClient with your credentials. AuthClient authClient = new AuthClient.Builder .clientId(clientId) .clientSecret(clientSecret) .mode(mode); // Retrieve the auth URL to start the OAuth flow. String authUrl = authClient.authUrlBuilder() .setApprovalPrompt(true) .setState("some state") .build();
-
Allow the user to complete their portion of the OAuth flow using the generated URL.
-
Once the user is sent back to the redirect url, the required authorization code will be included in the query string:
https://redirect-url.example.com/?code=<AUTHORIZATION_CODE> -
Given the authorization code, you can now exchange it for an authorization token which can be used to access the Smartcar platform:
Auth auth = authClient.exchangeCode(code);
Now that you have authenticated and can access the Smartcar platform, you can start making requests to vehicles.
-
Obtain a list of authorized vehicles:
VehicleIds response = AuthClient.getVehicleIds(auth.getAccessToken()); String[] vehicleIds = response.getVehicleIds();
-
Create an instance of
Vehicle:Vehicle vehicle = new Vehicle(vehicleIds[0], auth.getAccessToken());
-
You can now access all information about the specified vehicle:
// Retrieve the vehicle's VIN String vin = vehicle.vin().getVin(); // Read the vehicle's odometer VehicleOdometer odometerData = vehicle.odometer(); double odometer = odometerData.getDistance(); // Retrieve the vehicle's location VehicleLocation locationData = vehicle.location(); String latLong = locationData.getLatitude() + ", " + locationData.getLongitude(); // Lock and unlock the vehicle vehicle.lock(); vehicle.unlock();
Smartcar aims to support the SDK on all LTS Java releases (and Java 8) until the "Extended Support" date as defined in the Oracle Java SE Support Roadmap
In accordance with the Semantic Versioning specification, the addition of support for new Java releases would result in a MINOR version bump and the removal of support for Java releases would result in a MAJOR version bump.
This project uses Gradle 7.6.4 and requires Java 8+ for development (Java 17+ for CI/CD).
# Build the project
./gradlew build
# Run tests
./gradlew test
# Run integration tests
./gradlew integrationThis SDK is published to Maven Central using the Sonatype Central Portal (the modern replacement for OSSRH). The publishing process is automated through our CI/CD pipeline but requires manual approval.
-
Automated Upload: When code is pushed to
master, our CI pipeline automatically:- Builds and signs the artifacts using PGP
- Uploads to Sonatype Central Portal for validation
- Creates a git tag for the release
-
Manual Publishing: After upload validation succeeds:
- Visit the Sonatype Central Portal
- Review the uploaded artifacts
- Click "Publish" to release to Maven Central
- Artifacts sync to Maven Central within 10-30 minutes
For testing the publishing process locally:
# Ensure signing keys are configured (see CONTRIBUTING.md)
export ORG_GRADLE_PROJECT_signingKey="$(cat private-key.asc)"
export ORG_GRADLE_PROJECT_signingPassword="your-key-password"
export ORG_GRADLE_PROJECT_sonatypeUsername="your-sonatype-username"
export ORG_GRADLE_PROJECT_sonatypePassword="your-sonatype-password"
# Upload to Sonatype Central
./gradlew uploadToSonatypeCentralFor detailed development and contribution guidelines, see CONTRIBUTING.md.