Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NoClassDefFoundError when running mvn liquibase:update #66

Closed
olavloite opened this issue Feb 23, 2021 · 4 comments · Fixed by googleapis/java-spanner#950
Closed
Assignees
Labels
bug Something isn't working

Comments

@olavloite
Copy link
Collaborator

The following error can occur when using version 1.0.1 of the Liquibase integration.

java.lang.NoClassDefFoundError: com/google/spanner/admin/database/v1/DatabaseAdminGrpc: com.google.spanner.admin.database.v1.DatabaseAdminGrpc
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Exception in thread "SpannerPool shutdown hook" java.lang.NoClassDefFoundError: com/google/cloud/spanner/connection/SpannerPool$CheckAndCloseSpannersMode
	at com.google.cloud.spanner.connection.SpannerPool$CloseSpannerRunnable.run(SpannerPool.java:95)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassNotFoundException: com.google.cloud.spanner.connection.SpannerPool$CheckAndCloseSpannersMode
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
	... 2 more

This is caused by a missing internal dependency in the JDBC driver. A workaround for this problem is to add the following dependency to your project:

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-spanner-jdbc</artifactId>
  <version>1.20.0</version>
</dependency>
@olavloite olavloite added the bug Something isn't working label Feb 23, 2021
@olavloite olavloite self-assigned this Feb 23, 2021
@olavloite
Copy link
Collaborator Author

Fixed in 1.0.2.

@tfindlay-au
Copy link

Using 1.0.2 did not solve this problem for me.

    <plugins>
      <plugin>
        <groupId>org.liquibase</groupId>
        <artifactId>liquibase-maven-plugin</artifactId>
        <version>4.3.1</version>
        <dependencies>
          <dependency>
            <groupId>com.google.cloudspannerecosystem</groupId>
            <artifactId>liquibase-spanner</artifactId>
            <version>1.0.2</version>
            <scope>compile</scope>
          </dependency>
        </dependencies>
        <configuration>
          <propertyFile>src/main/resources/liquibase.properties</propertyFile>
        </configuration>
      </plugin>

Returned the same exception:

Exception in thread "SpannerPool shutdown hook" java.lang.NoClassDefFoundError: com/google/cloud/spanner/connection/SpannerPool$CheckAndCloseSpannersMode
        at com.google.cloud.spanner.connection.SpannerPool$CloseSpannerRunnable.run(SpannerPool.java:106)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.ClassNotFoundException: com.google.cloud.spanner.connection.SpannerPool$CheckAndCloseSpannersMode
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
        ... 2 more

Adding the dependency on google-cloud-spanner-jdbc did not seem to resolve the issue either.
Was it correct to try and add that as a dependency of the plugin ?

@olavloite
Copy link
Collaborator Author

Using 1.0.2 did not solve this problem for me.

I've just tried it out locally, and I think the problem is slightly different (and a lot less severe) in 1.0.2:

  1. The original problem also included a class loading problem for java.lang.NoClassDefFoundError: com/google/spanner/admin/database/v1/DatabaseAdminGrpc: com.google.spanner.admin.database.v1.DatabaseAdminGrpc. That prevented the Liquibase plugin to run at all, and the mvn liquibase:update command would not execute any updates.
  2. The problem now seems to only be a ClassNotFoundException for com/google/cloud/spanner/connection/SpannerPool$CheckAndCloseSpannersMode during the shutdown hook that is registered in the JDBC driver. That should not stop Liquibase from running the actual update. It only generates an error when Liquibase is shutting down.

At least for me locally Liquibase does start and creates the change log and lock tables, and then executes the master change log.

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------< com.google.cloud:spanner-liquibase-sample >--------------
[INFO] Building Spanner Liquibase Sample 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- liquibase-maven-plugin:4.3.1:update (default-cli) @ spanner-liquibase-sample ---
[INFO] ------------------------------------------------------------------------
[INFO] there are no resolved artifacts for the Maven project.
[INFO] there are no resolved artifacts for the Maven project.
[project, pluginDescriptor]
[INFO] Parsing Liquibase Properties File
[INFO]   File: src/main/resources/liquibase.properties
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] 
[INFO] Liquibase Community 4.3.1 by Datical
[INFO] ####################################################
##   _     _             _ _                      ##
##  | |   (_)           (_) |                     ##
##  | |    _  __ _ _   _ _| |__   __ _ ___  ___   ##
##  | |   | |/ _` | | | | | '_ \ / _` / __|/ _ \  ##
##  | |___| | (_| | |_| | | |_) | (_| \__ \  __/  ##
##  \_____/_|\__, |\__,_|_|_.__/ \__,_|___/\___|  ##
##              | |                               ##
##              |_|                               ##
##                                                ## 
##  Get documentation at docs.liquibase.com       ##
##  Get certified courses at learn.liquibase.com  ## 
##  Free schema change activity reports at        ##
##      https://hub.liquibase.com                 ##
##                                                ##
####################################################
Starting Liquibase at 11:28:22 (version 4.3.1 #26 built at 2021-02-12 17:41+0000)
[INFO] Parsing Liquibase Properties File src/main/resources/liquibase.properties for changeLog parameters
[INFO] Executing on Database: jdbc:cloudspanner://localhost:9010/projects/test-project/instances/test-instance/databases/test-db?usePlainText=true
[INFO] Successfully acquired change log lock
[INFO] Creating database history table with name: DATABASECHANGELOG
[INFO] Reading from DATABASECHANGELOG
[INFO] Successfully released change log lock
[INFO] Successfully acquired change log lock
Skipping auto-registration
[WARNING] Skipping auto-registration
[INFO] Table rollback_table created
[INFO] ChangeSet db.changelog-master.yaml::rollback-test::liquibase-docs ran successfully in 12ms
[INFO] Successfully released change log lock
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.220 s
[INFO] Finished at: 2021-03-11T11:28:24+01:00
[INFO] ------------------------------------------------------------------------
Exception in thread "SpannerPool shutdown hook" java.lang.NoClassDefFoundError: com/google/cloud/spanner/connection/SpannerPool$CheckAndCloseSpannersMode
	at com.google.cloud.spanner.connection.SpannerPool$CloseSpannerRunnable.run(SpannerPool.java:96)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassNotFoundException: com.google.cloud.spanner.connection.SpannerPool$CheckAndCloseSpannersMode
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
	... 2 more

Shutdown hooks are known to be best-effort. The shutdown hook of the JDBC driver tries to delete all Spanner sessions that have been opened during the lifetime of the JVM. Failing to do so will not cause any real harm, as the sessions will be garbage collected by the backend after 1 hour anyways, but common practice is to clean up as much as possible.

I've created an issue for it in the Spanner client library. The most probable solution will be to just ignore any error in the shutdown hook and not reporting it, as the current situation only creates confusion, while there is nothing really actionable in this case.

@olavloite
Copy link
Collaborator Author

Adding the dependency on google-cloud-spanner-jdbc did not seem to resolve the issue either.
Was it correct to try and add that as a dependency of the plugin ?

Adding the dependency should not be necessary in 1.0.2, as the JDBC driver is automatically included in the Liquibase plugin. The reason that adding version 1.20.0 of the JDBC driver was a workaround in version 1.0.1, was that the underlying problem was caused by the Spanner client library that was used by JDBC driver version 1.19.0. So the workaround was just an override of the version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants