diff --git a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
index acd1611797f7..d19faa88e457 100644
--- a/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
+++ b/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
@@ -149,7 +149,7 @@ public B clock(Clock clock) {
}
/**
- * Sets project id.
+ * Sets project ID.
*
* @return the builder
*/
@@ -235,7 +235,18 @@ protected boolean projectIdRequired() {
return true;
}
- private static AuthCredentials defaultAuthCredentials() {
+ /**
+ * Returns the default authentication credentials, or {@code null} if no default credentials could
+ * be found. This method returns the first available credentials among the following sources:
+ *
+ * - App Engine credentials
+ *
- JSON credentials pointed to by the {@code GOOGLE_APPLICATION_CREDENTIALS} environment
+ * variable
+ *
- Google Cloud SDK credentials
+ *
- Compute Engine credentials
+ *
+ */
+ public static AuthCredentials defaultAuthCredentials() {
// Consider App Engine.
if (appEngineAppId() != null) {
try {
@@ -261,6 +272,21 @@ protected String defaultHost() {
}
protected String defaultProject() {
+ return defaultProjectId();
+ }
+
+ /**
+ * Returns the default project ID, or {@code null} if no default project ID could be found. This
+ * method returns the first available project ID among the following sources:
+ *
+ * - App Engine project ID
+ *
- Project ID specified in the JSON credentials file pointed by the
+ * {@code GOOGLE_APPLICATION_CREDENTIALS} environment variable
+ *
- Google Cloud SDK project ID
+ *
- Compute Engine project ID
+ *
+ */
+ public static String defaultProjectId() {
String projectId = System.getProperty(PROJECT_ENV_NAME, System.getenv(PROJECT_ENV_NAME));
if (projectId == null) {
projectId =
@@ -402,8 +428,8 @@ public ServiceRpcT rpc() {
}
/**
- * Returns the project id. Return value can be null (for services that don't require a project
- * id).
+ * Returns the project ID. Return value can be null (for services that don't require a project
+ * ID).
*/
public String projectId() {
return projectId;