Repository navigation
ClassNotFoundException when using com.google.gcloud.AuthCredentials in 0.0.9 #260
Description
Activity
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>I tried but I couldn't reproduce your error.
Could you share the complete stacktrace and the code you are using and possibly yourpom.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.xmlis:<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.
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$WrappedPrintStreamI 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.serDecompiling 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; ...
You are right, I was using a locally installed artifact that does not have that problem.
Must be an issue with our deploy process,coberturastuff remains in deployed class files. I will look into it, sorry for inconvenient, I'll keep you posted.This problem seems to have started with
0.0.9. To add some background:mvn compilecompiles classes intarget/classes.mvn cobertura:coberturainstruments classes and places the compiled ones intotarget/generated-classes/cobertura. Intarget/generated-classes/coberturawe have class files and acobertura.propertiesfile.
Looking at the deployed jars it seems that they are being generated from the class files in
target/generated-classses/cobertura: they containcobertura.propertiesand classes contain cobertura code (see the decompiled AuthCredentails here).The problem comes from
mvn sitewhich (I don't know why) creates the jars for the classes intarget/generated-classes/cobertura. Themvn deploycommand 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-deployThat should delete wrong jars and force building new ones. @ajkannan @aozarov what do you think?
Thanks again to @simon-temple for spotting this!
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 JARsSince we copy the signing tools into the directory
target/travis, those will get erased bycleanbefore they can be used to deploy. As long as we move those to another location, this fix sounds good to me.I'm assigning myself the issue, and I'll test @mziccard's solution.
Thanks @ajkannan, you are right, we might need to move signing tools elsewhere, but that should no be an issue.
@simon-temple We fixed the issue and deployed version 0.0.10!
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$WrappedPrintStreamIf the gcloud POM dependencies are correct shouldn't it be included by maven when it resolves all my dependencies?
guavais 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 compilemvn exec:java -Dexec.mainClass="com.mycompany.app.App"
At
mvn compileI see guava being downloaded and installed,mvn exec...then runs the app smoothly.- deleted my local repo with
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.
26 remaining items
- added 2 commits that reference this issue
on Oct 5, 2022 - added a commit that references this issue
on Nov 8, 2022 - added a commit that references this issue
on Nov 19, 2022 - added a commit that references this issue
on Dec 22, 2025 - added a commit that references this issue
on Jan 6, 2026 - added a commit that references this issue
on Jan 22, 2026 - added a commit that references this issue
on Feb 24, 2026 - added a commit that references this issue
on Mar 12, 2026 - added a commit that references this issue
on Mar 23, 2026 - added 2 commits that reference this issue
on Mar 30, 2026 - added 2 commits that reference this issue
on Apr 1, 2026
I've just upgraded to 0.0.9 from 0.0.8-SNAPSHOT and I get
calling