liquibase-maven-plugin liquibase:diff - 不工作(在类路径中找不到任何META-INF / persistence.xml文件)

时间:2014-07-30 18:09:17

标签: spring hibernate maven jpa liquibase

我很难运行liquibase:diff通过liquibase-maven-plugin

我有一个使用spring-boot引导的基于Spring Data JPA的应用程序。所以,不会有任何persistence.xml

以下是pom.xml的片段:

<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.2.2</version>
<configuration>
    <propertyFile>target/classes/liquibase.properties</propertyFile>
</configuration>
<dependencies>
    <dependency>
    <groupId>org.liquibase.ext</groupId>
    <artifactId>liquibase-hibernate4</artifactId>
    <version>${liquibase_hibernate_version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>${mysql.version}</version>
    </dependency>
    <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${spring.version}</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>${hibernate.version}</version>
    </dependency>
    <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate-entitymanager.version}</version>
    </dependency>
</dependencies>

这是liquibase.properties:

changeLogFile: classpath:/db/changelog/changelog-master.xml
diffChangeLogFile: src/main/resources/db/changelog/changelog-sql-2_0.sql
driver: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/sample
defaultSchema: sample
username: root
password: root
referenceUrl: hibernate:spring:se.sample.core.domain?dialect=org.hibernate.dialect.MySQL5Dialect
verbose: true
dropFirst: false
logging: debug

这是我正在使用的maven命令:

mvn resources:resources liquibase:diff -Pprod

这是我得到的错误:

[INFO] Executing on Database: jdbc:mysql://localhost:3306/sample
INFO 7/30/14 2:47 PM: liquibase-hibernate: Reading hibernate configuration hibernate:spring:se.sample.core.domain?dialect=org.hibernate.dialect.MySQL5Dialect
INFO 7/30/14 2:47 PM: liquibase-hibernate: Found package se.sample.core.domain
INFO 7/30/14 2:47 PM: liquibase-hibernate: Found dialect org.hibernate.dialect.MySQL5Dialect
Jul 30, 2014 2:47:21 PM org.hibernate.jpa.boot.internal.PersistenceXmlParser doResolve
**INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath**
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.095s
[INFO] Finished at: Wed Jul 30 19:38:38 CEST 2014
[INFO] Final Memory: 18M/310M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.2.2:diff (default-cli) on project fmu-core: Error setting up or running Liquibase: java.lang.NullPointerException -> [Help 1]
[ERROR] 

由于我使用Spring JPA而没有任何persistence.xml,所以我无法理解如何使它工作。

有人可以指导吗?

更新1

在maven命令中添加-X以获取完整的详细信息:

INFO: HHH000318: Could not find any META-INF/persistence.xml file in the classpath
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.192s
[INFO] Finished at: Wed Jul 30 20:20:24 CEST 2014
[INFO] Final Memory: 21M/433M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.2.2:diff (default-cli) on project fmu-core: Error setting up or running Liquibase: java.lang.NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.liquibase:liquibase-maven-plugin:3.2.2:diff (default-cli) on project fmu-core: Error setting up or running Liquibase: java.lang.NullPointerException
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
    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:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    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:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Error setting up or running Liquibase: java.lang.NullPointerException
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:371)
    at org.liquibase.maven.plugins.LiquibaseDatabaseDiff.execute(LiquibaseDatabaseDiff.java:129)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more
Caused by: liquibase.exception.DatabaseException: java.lang.NullPointerException
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:53)
    at org.liquibase.maven.plugins.LiquibaseDatabaseDiff.performLiquibaseTask(LiquibaseDatabaseDiff.java:144)
    at org.liquibase.maven.plugins.AbstractLiquibaseMojo.execute(AbstractLiquibaseMojo.java:367)
    ... 22 more
Caused by: java.lang.NullPointerException
    at liquibase.ext.hibernate.database.HibernateSpringDatabase.buildConfigurationFromScanning(HibernateSpringDatabase.java:237)
    at liquibase.ext.hibernate.database.HibernateSpringDatabase.buildConfiguration(HibernateSpringDatabase.java:56)
    at liquibase.ext.hibernate.database.HibernateDatabase.setConnection(HibernateDatabase.java:42)
    at liquibase.database.DatabaseFactory.findCorrectDatabaseImplementation(DatabaseFactory.java:123)
    at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:141)
    at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:44)
    ... 24 more

2 个答案:

答案 0 :(得分:1)

我不确定您的配置有什么问题,可能是该版本中的错误或其他问题。所以我分享了我刚开始工作的那个。你可以找到full source here,但下面应该是相关的细节。

这是我的liquibase.properties

referenceUrl=hibernate:spring:com.xenoterracide?dialect=org.hibernate.dialect.H2Dialect
changeLogFile: classpath:changelog.db-master.xml
diffChangeLogFile: changelog.xml
driver: org.h2.Driver
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
username: sa
password:
verbose: true
logging: debug

我的pom.xml中的插件配置(版本来自spring platform-b​​om)

<build>
<plugins>
  <plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>${liquibase.version}</version>
    <configuration>
      <propertyFile>liquibase.properties</propertyFile>
    </configuration>
     <dependencies>
      <dependency> <!-- optional but may use different version of hibernate than you do if not specified -->
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${spring.version}</version>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>${spring.version}</version>
      </dependency>
      <dependency>
        <groupId>org.liquibase.ext</groupId>
        <artifactId>liquibase-hibernate4</artifactId>
        <version>3.5</version>
      </dependency>
    </dependencies>
  </plugin>
</plugins>
</build>

答案 1 :(得分:-1)

为什么你认为这应该有效?

如果Spring Data通过支持没有META-INF/persistence.xml的持久性单元以不合规的方式扩展JPA规范,为什么Liquibase或任何其他兼容的应用程序也应该这样做?