Maven usage of google api

13,779

Solution 1

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.

Solution 2

I had adventure with google custom search api. Most of the problem were due to unavailability of mvn repo http://google-api-client-libraries.appspot.com/mavenrepo.

Custom search jar I took from:

<repository>
  <id>google-api-services</id>
  <url>http://mavenrepo.google-api-java-client.googlecode.com/hg</url>
</repository>

It was in pom inside the jar downloaded manually. Newest google-api-client and google-http-client-jackson (at 1.13.2-beta JacksonFactory is an additional dependency) were in central maven repo.

Share:
13,779
m09
Author by

m09

Updated on June 16, 2022

Comments

  • m09
    m09 about 2 years

    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.

  • m09
    m09 over 11 years
    Sadly it doesn't change anything for me. Is there a special manipulation to perform so that maven correctly reconsiders all the dependencies?
  • Anders R. Bystrup
    Anders R. Bystrup over 11 years
    Try deleting or renaming your .m2 directory and re-run mvn. Sometimes a bad POM can wreak havoc...
  • m09
    m09 over 11 years
    arghz, still nothing (well, nothing = the same classes not found). :(
  • Anders R. Bystrup
    Anders R. Bystrup over 11 years
    I added a few deps that probably really should be transient, but aren't... Hope that brings you home.
  • m09
    m09 over 11 years
    yup sorry I didn't report here yet but I got helped on IRC and those deps came about. Thanks a lot for the help, it's very appreciated.
  • Goran Jovic
    Goran Jovic over 11 years
    Thank you! I've been searching for JacksonFactory all day.