8

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
  • 7,490
  • 3
  • 31
  • 58
  • Maven doesn't compile anything, the maven-compiler plugin does. You're likely missing some dependencies - post your POM, your maven commandline used and more of the maven trace, please. – Anders R. Bystrup Dec 01 '12 at 19:23
  • done. (I tried adding the oauth library, for example, but to no avail.) – m09 Dec 01 '12 at 19:28
  • Could you try using the "official" googlecode repo instead: `https://oss.sonatype.org/content/repositories/releases/` – Anders R. Bystrup Dec 01 '12 at 19:37
  • no change. What would be the correct way to add them locally under maven management? – m09 Dec 01 '12 at 19:41
  • Have you figured out which artifact(s) contain the missing packages? You should add them as dependencies in the POM if the google-api-client doesn't name them. Post your `maven package` output or link to it. – Anders R. Bystrup Dec 01 '12 at 19:43
  • and if I name them it'll still find them on the repo? – m09 Dec 01 '12 at 19:50

3 Answers3

14

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.

Anders R. Bystrup
  • 15,729
  • 10
  • 59
  • 55
  • Sadly it doesn't change anything for me. Is there a special manipulation to perform so that maven correctly reconsiders all the dependencies? – m09 Dec 01 '12 at 20:07
  • Try deleting or renaming your .m2 directory and re-run mvn. Sometimes a bad POM can wreak havoc... – Anders R. Bystrup Dec 01 '12 at 20:23
  • arghz, still nothing (well, nothing = the same classes not found). :( – m09 Dec 01 '12 at 20:28
  • I added a few deps that probably really should be transient, but aren't... Hope that brings you home. – Anders R. Bystrup Dec 02 '12 at 09:36
  • 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. – m09 Dec 02 '12 at 09:41
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.

Waldemar Wosiński
  • 1,490
  • 17
  • 28
0

As of a few months ago, Google started pushing libraries to the Sonatype repo. You no longer should include a repository entry in your pom.xml pointing to google-api-client-libraries.appspot.com/mavenrepo or mavenrepo.google-api-java-client.googlecode.com

Doing that slows down your builds because you end up checking for all dependencies (even non Google ones) at that repository. These checks 404, then you check the master repository.