0

问题

我使用描述我的数据库对象结构的 YAML 脚本。这非常方便,因为我可以使用 H2 进行基于 DB 的集成测试。

但是我的客户的生产服务要求我们提供面向 Oracle 的 SQL 脚本(他们使用 Liquibase,但以非标准方式,我们无法挑战/更改)。

因此,我想以自动方式从我的 YAML 脚本生成这些 Oracle SQL 脚本。

想法

我首先找到了Liquibase:updateSQL 命令。问题是我无权访问数据库(我不知道 JDBC URL,我也不在同一个网络上)。所以这个解决方案是行不通的。

然后,我在 Liquibase 中发现了一个新选项,它允许updateSQL 命令的“离线”模式。这似乎确实是我正在寻找的解决方案,但随后出现以下错误(使用 Maven 和 -X -e 选项):

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL (default-cli) on project granit: Error setting up or running Liquibase: liquibase.exception.UnexpectedLiquibaseException: java.lang.NoSuchMethodException: liquibase.database.OfflineConnection.getWrappedConnection() -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL (default-cli) on project granit: Error setting up or running Liquibase: liquibase.exception.UnexpectedLiquibaseException: java.lang.NoSuchMethodException: liquibase.database.OfflineConnection.getWrappedConnection()
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error setting up or running Liquibase: liquibase.exception.UnexpectedLiquibaseException: java.lang.NoSuchMethodException: liquibase.database.OfflineConnection.getWrappedConnection()
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:373)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more
Caused by: liquibase.exception.DatabaseException: liquibase.exception.UnexpectedLiquibaseException: java.lang.NoSuchMethodException: liquibase.database.OfflineConnection.getWrappedConnection()
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:69)
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:321)
    ... 21 more
Caused by: liquibase.exception.UnexpectedLiquibaseException: java.lang.NoSuchMethodException: liquibase.database.OfflineConnection.getWrappedConnection()
    at liquibase.database.core.OracleDatabase.setConnection(OracleDatabase.java:62)
    at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:123)
    at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:143)
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:50)
    ... 22 more
Caused by: java.lang.NoSuchMethodException: liquibase.database.OfflineConnection.getWrappedConnection()
    at java.lang.Class.getMethod(Class.java:1624)
    at liquibase.database.core.OracleDatabase.setConnection(OracleDatabase.java:58)
    ... 25 more

然后我重新尝试离线 H2 基地,但我有一个新的错误:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.748 s
[INFO] Finished at: 2015-02-22T12:00:51+01:00
[INFO] Final Memory: 19M/123M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL (default-cli) on project app: Execution default-cli of goal org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL failed: A required class was missing while executing org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL: org/yaml/snakeyaml/Yaml
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.liquibase:liquibase-maven-plugin:3.3.2
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/Users/me/.m2/repository/org/liquibase/liquibase-maven-plugin/3.3.2/liquibase-maven-plugin-3.3.2.jar
[ERROR] urls[1] = file:/Users/me/.m2/repository/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.jar
[ERROR] urls[2] = file:/Users/me/.m2/repository/org/liquibase/liquibase-core/3.3.2/liquibase-core-3.3.2.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import  from realm ClassRealm[project>fr.cnp.grn:app:1.0.14-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]
[ERROR] 
    [ERROR] -----------------------------------------------------: org.yaml.snakeyaml.Yaml
    [ERROR] -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL (default-cli) on project app: Execution default-cli of goal org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL failed: A required class was missing while executing org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL: org/yaml/snakeyaml/Yaml
    -----------------------------------------------------
    realm =    plugin>org.liquibase:liquibase-maven-plugin:3.3.2
    strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
    urls[0] = file:/Users/me/.m2/repository/org/liquibase/liquibase-maven-plugin/3.3.2/liquibase-maven-plugin-3.3.2.jar
    urls[1] = file:/Users/me/.m2/repository/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.jar
    urls[2] = file:/Users/me/.m2/repository/org/liquibase/liquibase-core/3.3.2/liquibase-core-3.3.2.jar
    Number of foreign imports: 1
    import: Entry[import  from realm ClassRealm[project>fr.cnp.grn:app:1.0.14-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

    -----------------------------------------------------

        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
    Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-cli of goal org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL failed: A required class was missing while executing org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL: org/yaml/snakeyaml/Yaml
    -----------------------------------------------------
    realm =    plugin>org.liquibase:liquibase-maven-plugin:3.3.2
    strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
    urls[0] = file:/Users/me/.m2/repository/org/liquibase/liquibase-maven-plugin/3.3.2/liquibase-maven-plugin-3.3.2.jar
    urls[1] = file:/Users/me/.m2/repository/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.jar
    urls[2] = file:/Users/me/.m2/repository/org/liquibase/liquibase-core/3.3.2/liquibase-core-3.3.2.jar
    Number of foreign imports: 1
    import: Entry[import  from realm ClassRealm[project>fr.cnp.grn:app:1.0.14-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

    -----------------------------------------------------

        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:167)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 19 more
    Caused by: org.apache.maven.plugin.PluginContainerException: A required class was missing while executing org.liquibase:liquibase-maven-plugin:3.3.2:updateSQL: org/yaml/snakeyaml/Yaml
    -----------------------------------------------------
    realm =    plugin>org.liquibase:liquibase-maven-plugin:3.3.2
    strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
    urls[0] = file:/Users/me/.m2/repository/org/liquibase/liquibase-maven-plugin/3.3.2/liquibase-maven-plugin-3.3.2.jar
    urls[1] = file:/Users/me/.m2/repository/org/codehaus/plexus/plexus-utils/1.0.4/plexus-utils-1.0.4.jar
    urls[2] = file:/Users/me/.m2/repository/org/liquibase/liquibase-core/3.3.2/liquibase-core-3.3.2.jar
    Number of foreign imports: 1
    import: Entry[import  from realm ClassRealm[project>fr.cnp.grn:app:1.0.14-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

    -----------------------------------------------------

        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:165)
        ... 20 more
    Caused by: java.lang.NoClassDefFoundError: org/yaml/snakeyaml/Yaml
        at liquibase.parser.core.yaml.YamlChangeLogParser.parse(YamlChangeLogParser.java:44)
        at liquibase.changelog.DatabaseChangeLog.include(DatabaseChangeLog.java:356)
        at liquibase.changelog.DatabaseChangeLog.handleChildNode(DatabaseChangeLog.java:248)
        at liquibase.changelog.DatabaseChangeLog.load(DatabaseChangeLog.java:211)
        at liquibase.parser.core.xml.AbstractChangeLogParser.parse(AbstractChangeLogParser.java:25)
        at liquibase.Liquibase.getDatabaseChangeLog(Liquibase.java:215)
        at liquibase.Liquibase.update(Liquibase.java:192)
        at liquibase.Liquibase.update(Liquibase.java:258)
        at org.liquibase.maven.plugins.LiquibaseUpdateSQL.doUpdate(LiquibaseUpdateSQL.java:49)
        at org.liquibase.maven.plugins.AbstractLiquibaseUpdateMojo.performLiquibaseTask(AbstractLiquibaseUpdateMojo.java:24)
        at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:369)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
        ... 20 more
    Caused by: java.lang.ClassNotFoundException: org.yaml.snakeyaml.Yaml
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:259)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:235)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:227)
        ... 32 more

所以我的问题是:

  1. Liquibase:updateSQL 在您看来是正确的解决方案吗?
  2. 您是否成功在 Oracle 的离线模式下执行 Liquibase:updateSQL 命令?(如何 ?)

感谢您到目前为止的阅读

4

0 回答 0