首页 文章

无法通过我的spring maven项目集成和运行liquibase

提问于
浏览
0

我试图通过我的基于Spring的 maven 项目运行 mvn liquibase:update . 但我看到以下错误 .

Error:

$ mvn liquibase:update
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=386m; support was removed in 8.0
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building liquibase-samples 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- liquibase-maven-plugin:3.0.5:update (default-cli) @ liquibase-samples ---
[INFO] ------------------------------------------------------------------------
[INFO] Parsing Liquibase Properties File
[INFO]   File: src/main/resources/liquibase/liquibase.properties
[INFO] ------------------------------------------------------------------------
[INFO] Executing on Database: jdbc:postgresql://gsi-547576:5432/emp-db
INFO 5/15/17 4:30 PM:liquibase: null: null: Successfully acquired change log lock
SEVERE 5/15/17 4:30 PM:liquibase: null: null: cvc-elt.1: Cannot find the declaration of element 'databaseChangeLog'.
INFO 5/15/17 4:30 PM:liquibase: null: null: Successfully released change log lock
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.225 s
[INFO] Finished at: 2017-05-15T16:30:09-04:00
[INFO] Final Memory: 14M/1011M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.0.5:update (default-cli) on project liquibase-samples: Error setting up or running Liquibase: Error parsing line 5 column 91 of src/main/resources/liquibase/db-changelog-master.xml: cvc-elt.1: Cannot find the declaration of element 'databaseChangeLog'. -> [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

以下是我的集成方式 .

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.study</groupId>
    <artifactId>liquibase-samples</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-core</artifactId>
            <version>3.5.3</version>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>9.3-1102-jdbc41</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>3.0.5</version>
                <configuration>
                    <propertyFile>src/main/resources/liquibase/liquibase.properties</propertyFile>
                    <changeLogFile>src/main/resources/liquibase/db-changelog-master.xml</changeLogFile>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>update</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

src/main/resources/liquibase/liquibase.properties

driver=org.postgresql.Driver
url=jdbc:postgresql://localhost:5432/emp-db
username=abc
password=abc

src/main/resources/liquibase/db-changelog-master.xml

<?xml version="1.0" encoding="utf-8" ?>
    <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                            http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
        <include file="liquibase/db-changelog-1.0.xml" relativeToChangelogFile="true"/> 
    </databaseChangeLog>

src/main/resources/liquibase/db-changelog-1.0.xml

<?xml version="1.0" encoding="utf-8" ?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

    <changeSet id="create_department" author="chandeln">
        <createTable tableName="department">
            <column name="id" type="int">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="name" type="varchar(50)">
                <constraints nullable="false" />
            </column>
        </createTable>
    </changeSet>

    <changeSet id="create_employee" author="chandeln">
        <createTable tableName="employee">
            <column name="id" type="int">
                <constraints primaryKey="true" nullable="false" />
            </column>
            <column name="emp_name" type="varchar(50)">
                <constraints nullable="false" />
            </column>
            <column name="dept" type="int"/>
        </createTable>
    </changeSet>

    <changeSet id="tag-1.0" author="sheng.w">
        <tagDatabase tag="1.0" />
    </changeSet>

</databaseChangeLog>

1 回答

  • 0

    以下帖子解决了我的问题 .

    Maven build failing with Liquibase: cvc-elt.1 declaration of element cannot be found

    依赖版本和插件版本都应该匹配 . 我的新pom如下所示 .

    pom.xml

    <dependencies>
            <dependency>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-core</artifactId>
                <version>3.5.3</version>
            </dependency>
            <dependency>
                <groupId>org.postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>9.3-1102-jdbc41</version>
                <scope>runtime</scope>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>3.5.3</version>
                    <configuration>
                        <propertyFile>src/main/resources/liquibase/liquibase.properties</propertyFile>
                        <changeLogFile>src/main/resources/liquibase/db-changelog-master.xml</changeLogFile>
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>update</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    

相关问题