Adding google-cloud-secretmanager dependency will cause Could not find or load main class error

I have a very simple gradle project. The source code can be found here.

In its current state, it works completely fine. I use ./gradlew assemble to build the jar file, and I use java -jar bsonl-to-mongo-cli-1.0-SNAPSHOT.jar to run the jar file.

However, if I add this under dependencies in build.gradle:

implementation ''

./gradlew assemble will still run and a jar will be built, but java -jar bsonl-to-mongo-cli-1.0-SNAPSHOT.jar will cause this error:

Error: Could not find or load main class com.saasquatch.bsonltomongocli.Main

Does anyone know what’s going on here?

Your java command does not specify a classpath that includes the dependencies.

Consider using the application plugin to create an executable package, which also includes a run task. The Application Plugin

Yeah I’ve already moved to the application plugin.

What I don’t understand, though, is why this is only a problem once I add the google-cloud-secretmanager dependency. Without that dependency it works fine, and the project already has a few dependencies.

Apologies, I opened your code in another tab, got distracted, and then forgot to look at it. I replied just based on what was presented here. I’ll take a closer look.

When adding the secretmanager dependency, one of the jars from the new dependencies causes signing information to be added to your jar. That information causes your jar to be partially signed and java doesn’t like it (sorry, I’m not an expert on signing/the java security manager so I cannot explain it in better terms). If I delete META-INF/SIGNINGC.* from the jar then it will run.

With those files present in the jar jarsigner fails to verify as well:

jarsigner -verify bsonl-to-mongo-cli-1.0-SNAPSHOT.jar
jarsigner: java.lang.SecurityException: Invalid signature file digest for Manifest main attributes