Skip to content

ClassNotFoundException when using com.google.gcloud.AuthCredentials in 0.0.9 #260

Description

@simon-temple

I've just upgraded to 0.0.9 from 0.0.8-SNAPSHOT and I get

java.lang.ClassNotFoundException: net.sourceforge.cobertura.coveragedata.TouchCollector

calling

AuthCredentials.createFor()

Activity

  1. simon-temple commented on Oct 15, 2015

    @simon-temple
    Author

    For now I've added this to my POM but...

     <dependency>
                <groupId>net.sourceforge.cobertura</groupId>
                <artifactId>cobertura</artifactId>
                <version>2.1.1</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm-tree</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm-commons</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm-util</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.ow2.asm</groupId>
                        <artifactId>asm-analysis</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>oro</groupId>
                        <artifactId>oro</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>jaxen</groupId>
                        <artifactId>jaxen</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.apache.ant</groupId>
                        <artifactId>ant</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.apache.ant</groupId>
                        <artifactId>ant-junit</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.mortbay.jetty</groupId>
                        <artifactId>servlet-api-2.5</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.mortbay.jetty</groupId>
                        <artifactId>jetty</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.mortbay.jetty</groupId>
                        <artifactId>jetty-util</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>com.sun</groupId>
                        <artifactId>tools</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-api</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>ch.qos.logback</groupId>
                        <artifactId>logback-classic</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>junit</groupId>
                        <artifactId>junit</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.apache.commons</groupId>
                        <artifactId>commons-lang3</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
  2. mziccard commented on Oct 15, 2015

    @mziccard
    Contributor

    I tried but I couldn't reproduce your error.
    Could you share the complete stacktrace and the code you are using and possibly your pom.xml?
    Here is the simple code I tried:

    KeyStore keystore = KeyStore.getInstance("PKCS12");
    keystore.load(Files.newInputStream(Paths.get(PATH_TO_P12_KEYSTORE)), KEYSTORE_PASSWORD.toCharArray());
    PrivateKey privateKey = (PrivateKey) keystore.getKey("privatekey", KEYSTORE_PASSWORD.toCharArray());
    StorageOptions.Builder temp = StorageOptions.builder().projectId(PROJECT_ID)
        .authCredentials(AuthCredentials.createFor(EMAIL, privateKey));
    Storage storage = StorageFactory.instance().get(temp.build());
    for (BlobInfo info : storage.list(BUCKET)) {
      System.out.println(info);
    }

    And the pom.xml is:

    <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/maven-v4_0_0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.mycompany.app</groupId>
      <artifactId>my-app</artifactId>
      <packaging>jar</packaging>
      <version>1.0-SNAPSHOT</version>
      <name>my-app</name>
      <url>http://maven.apache.org</url>
      <dependencies>
        <dependency>
          <groupId>com.google.gcloud</groupId>
          <artifactId>gcloud-java</artifactId>
          <version>0.0.9</version>
        </dependency>
      </dependencies>
    </project>

    This seems to work here.

  3. simon-temple commented on Oct 15, 2015

    @simon-temple
    Author

    Section of my code:

    import com.google.gcloud.AuthCredentials;
    import com.google.gcloud.RetryParams;
    import com.google.gcloud.datastore.*;
    
    106: PrivateKey pk = PkiUtils.pkcs8PemDecode( pemPrivateKey );
    107: AuthCredentials credentials = AuthCredentials.createFor( clientId, pk );
    108: RetryParams retryParams = RetryParams.getDefaultInstance();
    109: options = DatastoreOptions.builder()
             .retryParams( retryParams )
             .authCredentials( credentials )
             .build();
    110: Datastore datastore = DatastoreFactory.instance().get( options );

    Part of my POM:

    <dependency>
        <groupId>com.google.gcloud</groupId>
        <artifactId>gcloud-java</artifactId>
        <version>0.0.9</version>
    </dependency>
    

    Stack trace:

    java.lang.NoClassDefFoundError: net/sourceforge/cobertura/coveragedata/TouchCollector
        at com.google.gcloud.AuthCredentials.__cobertura_init(AuthCredentials.java)
        at com.google.gcloud.AuthCredentials.<clinit>(AuthCredentials.java)
        at com.acme.prod.core.persist.gce.GCEPersistentStorage.init(GCEPersistentStorage.java:107)
        at com.acme.prod.core.persist.gce.GCEPersistentStorage.create(GCEPersistentStorage.java:59)
        at com.acme.prod.core.persist.StorageFactory.create(StorageFactory.java:37)
        at com.acme.prod.core.persist.StorageFactory.create(StorageFactory.java:28)
        at com.acme.prod.app.App.main(App.java:70)
    Caused by: java.lang.ClassNotFoundException: net.sourceforge.cobertura.coveragedata.TouchCollector
        at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 7 more","class":"java.lang.Throwable$WrappedPrintStream
    

    I found a cobertura.properties file in the root of gcloud-java-core-0.0.9.jar

    #Generated by maven-cobertura-plugin for project com.google.gcloud:gcloud-java-core:jar:0.0.9
    #Fri Oct 09 00:08:23 UTC 2015
    net.sourceforge.cobertura.datafile=/home/travis/build/GoogleCloudPlatform/gcloud-java/gcloud-java-core/target/cobertura/cobertura.ser
    

    Decompiling the AuthCredentials class in gcloud-java-core-0.0.9.jar I see:

    import net.sourceforge.cobertura.coveragedata.LightClassmapListener;
    import net.sourceforge.cobertura.coveragedata.TouchCollector;
    
    public abstract class AuthCredentials
      implements Serializable
    {
      public static final transient int[] __cobertura_counters;
    ...
  4. mziccard commented on Oct 15, 2015

    @mziccard
    Contributor

    You are right, I was using a locally installed artifact that does not have that problem.
    Must be an issue with our deploy process, cobertura stuff remains in deployed class files. I will look into it, sorry for inconvenient, I'll keep you posted.

  5. mziccard commented on Oct 15, 2015

    @mziccard
    Contributor

    This problem seems to have started with 0.0.9. To add some background:

    • mvn compile compiles classes in target/classes.
    • mvn cobertura:cobertura instruments classes and places the compiled ones into target/generated-classes/cobertura. In target/generated-classes/cobertura we have class files and a cobertura.properties file.

    Looking at the deployed jars it seems that they are being generated from the class files in target/generated-classses/cobertura: they contain cobertura.properties and classes contain cobertura code (see the decompiled AuthCredentails here).

    The problem comes from mvn site which (I don't know why) creates the jars for the classes in target/generated-classes/cobertura. The mvn deploy command then deploys these jars.
    I think this issue could be solved by replacing the line here with:

    mvn clean deploy -DskipTests=true --settings target/travis/settings.xml -P sign-deploy
    

    That should delete wrong jars and force building new ones. @ajkannan @aozarov what do you think?

    Thanks again to @simon-temple for spotting this!

  6. simon-temple commented on Oct 15, 2015

    @simon-temple
    Author

    Thank you. Please keep me updated about any 0.0.10 release.
    We're getting ready to system test a product and I'd rather not run with cobertura instrumented JARs

  7. ajkannan commented on Oct 15, 2015

    @ajkannan

    Since we copy the signing tools into the directory target/travis, those will get erased by clean before they can be used to deploy. As long as we move those to another location, this fix sounds good to me.

  8. ajkannan commented on Oct 15, 2015

    @ajkannan

    I'm assigning myself the issue, and I'll test @mziccard's solution.

  9. self-assigned this
    on Oct 15, 2015
  10. mziccard commented on Oct 15, 2015

    @mziccard
    Contributor

    Thanks @ajkannan, you are right, we might need to move signing tools elsewhere, but that should no be an issue.

  11. mziccard commented on Oct 15, 2015

    @mziccard
    Contributor

    @simon-temple We fixed the issue and deployed version 0.0.10!

  12. simon-temple commented on Oct 16, 2015

    @simon-temple
    Author

    Thanks for the quick turnaround.

    One other packaging question...

    I'm having to add this to my POM:

    <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>18.0</version>
    </dependency>
    

    to avoid this:

    java.lang.NoClassDefFoundError: com/google/common/base/MoreObjects
    at com.google.gcloud.RetryParams.toString(RetryParams.java:284)
    at java.lang.String.valueOf(String.java:2994)
    at java.lang.StringBuilder.append(StringBuilder.java:131)
    at com.acme.app.core.persist.gce.GCEPersistentStorage.init(GCEPersistentStorage.java:120)
    at com.acme.app.core.persist.gce.GCEPersistentStorage.create(GCEPersistentStorage.java:59)
    at com.acme.app.core.persist.PersistentStorageFactory.create(PersistentStorageFactory.java:37)
    at com.acme.app.core.persist.PersistentStorageFactory.create(PersistentStorageFactory.java:28)
    at com.acme.app.app.App.main(App.java:70)
    Caused by: java.lang.ClassNotFoundException: com.google.common.base.MoreObjects
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 8 more","class":"java.lang.Throwable$WrappedPrintStream
    

    If the gcloud POM dependencies are correct shouldn't it be included by maven when it resolves all my dependencies?

  13. mziccard commented on Oct 16, 2015

    @mziccard
    Contributor

    guava is not added as a compile dependency in our POMs so maven should be able to resolve it automatically for your project.

    I tried with the simple setup described previously in #260 (comment):

    • deleted my local repo with
      rm -rf ~/.m2/repository/com/google/guava ~/.m2/repository/com/google/gcloud
    • mvn compile
    • mvn exec:java -Dexec.mainClass="com.mycompany.app.App"

    At mvn compile I see guava being downloaded and installed, mvn exec... then runs the app smoothly.

  14. simon-temple commented on Oct 16, 2015

    @simon-temple
    Author

    Looks like my problem, sorry.

    I have a com.googlecode.objectify dependency in the same project. It holds the dependency on guava 18.0. Not sure why maven chooses objectify as the owner of guava over gcloud...?

    When I exclude com.googlecode.objectify from my final target it drops guava... even though gcloud-core has it as a dependency.

    ...any way. My bad and thanks for looking.

  15. 26 remaining items

  16. added a commit that references this issue on Jan 6, 2026
  17. added a commit that references this issue on Jan 22, 2026
  18. added a commit that references this issue on Feb 24, 2026
    4e33076
  19. added a commit that references this issue on Mar 12, 2026
    d9c5c05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

🚨 criticalP0 critical issue. Requires immediate fixtriage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    Sponsor
    SponsoredKunjungi sekarang
    Promo