java.lang.NoSuchMethodError: com.google.api.client.googleapis.auth.oauth2.GoogleCredential - PullRequest
0 голосов
/ 06 июля 2019
> java.lang.NoSuchMethodError: com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault()Lcom/google/api/client/googleapis/auth/oauth2/GoogleCredential

Я сталкиваюсь с этой ошибкой при подключении облака SQL через Java из локальной основной программы Java

Это мой код:

 public static void main(String[] args) throws SQLNonTransientConnectionException,
        IOException, SQLException {

    String instanceConnectionName = "*******";
    String databaseName = "******";
    String IP_of_instance = "*****";
    String username = "***";
    String password = "******";

    String jdbcUrl = String.format(
            "jdbc:mysql://%s/%s?cloudSqlInstance=%s"
            + "&socketFactory=com.google.cloud.sql.mysql.SocketFactory&useSSL=false",
            IP_of_instance,
            databaseName,
            instanceConnectionName);

    Connection connection = DriverManager.getConnection(jdbcUrl, username, password);

    try (Statement statement = connection.createStatement()) {
        ResultSet resultSet = statement.executeQuery("SHOW TABLES");
        while (resultSet.next()) {
            System.out.println(resultSet.getString(1));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}

и у меня есть файл pom.

 <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>1.9.69</version>
    </dependency>
    <dependency>
        <groupId>org.httprpc</groupId>
        <artifactId>httprpc</artifactId>
        <version>6.3.3</version>
    </dependency>
    <!-- [START servlet] -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <type>jar</type>
        <scope>provided</scope>
    </dependency>
    <!-- [END servlet] -->
    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client-appengine</artifactId>
        <version>1.7.0-beta</version>
    </dependency>
    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>3.3.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-urlshortener</artifactId>
        <version>v1-rev57-1.25.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.8.0-beta</version>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
    <dependency>
        <groupId>com.healthmarketscience.sqlbuilder</groupId>
        <artifactId>sqlbuilder</artifactId>
        <version>3.0.0</version>
    </dependency>
    <!-- [START_EXCLUDE] -->
    <!-- Test Dependencies -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-testing</artifactId>
        <version>1.9.69</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-admin</artifactId>
        <version>6.8.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-stubs</artifactId>
        <version>1.9.69</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-tools-sdk</artifactId>
        <version>1.9.69</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>com.google.truth</groupId>
        <artifactId>truth</artifactId>
        <version>0.42</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.13-beta-1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>2.23.4</version>
        <scope>test</scope>
    </dependency>
    <dependency> <!-- Only used locally -->
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.42</version>
    </dependency>
    <dependency>
        <groupId>com.google.cloud.sql</groupId>
        <artifactId>mysql-socket-factory</artifactId>
        <version>1.0.12</version>
    </dependency>
    <!-- [END_EXCLUDE] -->
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20160810</version>
        <type>jar</type>
    </dependency>
</dependencies>
...