Maven usage of google api

m09 picture m09 · Dec 1, 2012 · Viewed 13.2k times · Source

I'm using the google calendar java API for a project.

The calendar part is fine, maven seems to download it and use it without any hassle.

My problem comes from the main dependency of this lib: the com.google.api.client api.

In particular, when I follow the instructions detailed at this page, maven can't compile my project properly:

package com.google.api.client.extensions.java6.auth.oauth2 does not exist
package com.google.api.client.extensions.jetty.auth.oauth2 does not exist
package com.google.api.client.json.jackson2 does not exist

It lacks several classes and thus can't compile the file while when I download the zip and add the .jar manually without using maven it works fine.

It's the first project I manage with maven and don't know how to go from there. Pointers would be appreciated.

edit post request --- here is my POM

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>fr.univnantes.atal.atcal</groupId>
  <artifactId>AtCal</artifactId>
  <version>0.1</version>
  <packaging>jar</packaging>

  <name>AtCal</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <repositories>
    <repository>
      <id>google-api-services</id>
      <url>http://google-api-client-libraries.appspot.com/mavenrepo</url>
    </repository>
  </repositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.api-client</groupId>
      <artifactId>google-api-client</artifactId>
      <version>1.12.0-beta</version>
    </dependency>
    <dependency>
      <groupId>com.google.apis</groupId>
      <artifactId>google-api-services-calendar</artifactId>
      <version>v3-rev20-1.12.0-beta</version>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement>
      <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <!-- best lock down version of the plugin too -->
      <configuration>
        <source>1.5</source>
        <target>1.5</target>
      </configuration>
    </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

I basicly added two dependencies: calendar and api client. It was the mentionned step to get things working on the doc.

Answer

Anders R. Bystrup picture Anders R. Bystrup · Dec 1, 2012

It seems that the seemingly very beta-ish google-api-services-calendar:v3-rev20-1.12.0-beta isn't pushed to the sontaype repository yet, but if you try to include both the recommended repo and the one mentioned under the Calendar API in your POM:

<repositories>
    <repository>
        <id>google-api-services</id>
        <url>https://oss.sonatype.org/content/repositories/releases/</url>
    </repository>
    <repository>
        <id>google-api-services-beta</id>
        <url>http://google-api-client-libraries.appspot.com/mavenrepo</url>
    </repository>
</repositories>

Also, the following additional dependencies seem to be necessary:

<dependency>
    <groupId>com.google.api-client</groupId>
    <artifactId>google-api-client-java6</artifactId>
    <version>1.12.0-beta</version>
</dependency>
<dependency>
    <groupId>com.google.oauth-client</groupId>
    <artifactId>google-oauth-client-jetty</artifactId>
    <version>1.12.0-beta</version>
</dependency>
<dependency>
    <groupId>com.google.http-client</groupId>
    <artifactId>google-http-client-jackson2</artifactId>
    <version>1.12.0-beta</version>
</dependency>

Hope that helps.