使用maven的liquibase插件错误

时间:2012-07-13 09:52:43

标签: maven liquibase

你好我是liquibase的新手,我在编译后导入一个现有的项目我得到这个构建失败,我无法理解原因和解决方案我正在尝试理解代码但我真的找到了这样做的问题。

这是运行mvn compile

后的结果
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for org.squashtest.tm:squashtest-csp-distribution:pom:1.2.0.RELEASE
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: ${project.groupId}:org.squashtest.csp.core.log4j:jar -> duplicate declaration of version ${project.version} @ line 419, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: ${project.groupId}:org.squashtest.csp.core.jetty.start.osgi:jar -> duplicate declaration of version ${project.version} @ line 424, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: ${project.groupId}:org.squashtest.csp.core.service:jar -> duplicate declaration of version ${project.version} @ line 450, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: ${project.groupId}:squashtest-csp-launcher:jar -> duplicate declaration of version ${project.version} @ line 455, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: ${project.groupId}:org.squashtest.csp.tm.web:war -> duplicate declaration of version ${project.version} @ line 461, column 17
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: ${project.groupId}:org.squashtest.csp.tm.service:jar -> duplicate declaration of version ${project.version} @ line 467, column 17
[WARNING] 'profiles.profile[build-mysql].plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.codehaus.mojo:sql-maven-plugin @ line 682, column 15
[WARNING] 'profiles.profile[build-mysql].plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.liquibase:liquibase-maven-plugin @ line 724, column 15
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building squashtest-tm-distribution 1.2.0.RELEASE
[INFO] ------------------------------------------------------------------------
[WARNING] Failed to retrieve plugin descriptor for org.codehaus.izpack:izpack-maven-plugin:1.0-alpha-5: Plugin org.codehaus.izpack:izpack-maven-plugin:1.0-alpha-5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.codehaus.izpack:izpack-maven-plugin:jar:1.0-alpha-5
[INFO] 
[INFO] --- liquibase-maven-plugin:2.0.1:update (default-cli) @ squashtest-csp-distribution ---
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2:12.500s
[INFO] Finished at: Fri Jul 13 10:25:08 GMT+01:00 2012
[INFO] Final Memory: 8M/19M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:2.0.1:update (default-cli) on project squashtest-csp-distribution: The driver has not been specified either as a parameter or in a properties file. -> [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/MojoFailureException

这是pom.xml liquibase部分:

 <!-- We first run a full install against MySQL -->
  <plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <configuration>
      <skip>${mysql.distro.skip}</skip>
    </configuration>
    <executions>
      <execution>
        <id>generate-mysql-full-install-script</id>
        <phase>process-resources</phase>
        <goals>
          <goal>updateSQL</goal>
        </goals>
        <configuration>
          <dropFirst>true</dropFirst>
          <changeLogFile>${master.changelog}</changeLogFile>
          <driver>com.mysql.jdbc.Driver</driver>
          <url>${liquibase.mysql.url}</url>
          <username>${liquibase.mysql.username}</username>
          <password>${liquibase.mysql.password}</password>
          <migrationSqlOutputFile>${database.script.directory}/mysql-full-install-

        version-${project.version}.sql</migrationSqlOutputFile>
        </configuration>
      </execution>
    </executions>
  </plugin>

        <!-- We now run an incremental install against MySQL -->
  <plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <configuration>
      <skip>${mysql.distro.skip}</skip>
    </configuration>
    <executions>
      <execution>
        <id>generate-mysql-0.15.0-script</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>updateSQL</goal>
        </goals>
        <configuration>
          <dropFirst>true</dropFirst>
          <changeLogFile>${upgrade.0.15.0.changelog}</changeLogFile>
          <driver>com.mysql.jdbc.Driver</driver>
          <url>${liquibase.mysql.url}</url>
          <username>${liquibase.mysql.username}</username>
          <password>${liquibase.mysql.password}</password>
          <migrationSqlOutputFile>${database.script.directory}/mysql-upgrade-
           to-0.15.0.sql</migrationSqlOutputFile>
        </configuration>
      </execution>

      <execution>
        <id>generate-mysql-0.17.0-script</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>updateSQL</goal>
        </goals>
        <configuration>
          <dropFirst>false</dropFirst>
          <changeLogFile>${upgrade.0.17.0.changelog}</changeLogFile>
          <driver>com.mysql.jdbc.Driver</driver>
          <url>${liquibase.mysql.url}</url>
          <username>${liquibase.mysql.username}</username>
          <password>${liquibase.mysql.password}</password>
          <migrationSqlOutputFile>${database.script.directory}/mysql-upgrade-
           to-0.17.0.sql</migrationSqlOutputFile>
        </configuration>
      </execution>

      <execution>
        <id>generate-mysql-0.20.0-script</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>updateSQL</goal>
        </goals>
        <configuration>
          <dropFirst>false</dropFirst>
          <changeLogFile>${upgrade.0.20.0.changelog}</changeLogFile>
          <driver>com.mysql.jdbc.Driver</driver>
          <url>${liquibase.mysql.url}</url>
          <username>${liquibase.mysql.username}</username>
          <password>${liquibase.mysql.password}</password>
          <migrationSqlOutputFile>${database.script.directory}/mysql-upgrade-
           to-0.20.0.sql</migrationSqlOutputFile>
        </configuration>
      </execution>

      <execution>
        <id>generate-mysql-0.23.0-script</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>updateSQL</goal>
        </goals>
        <configuration>
          <dropFirst>false</dropFirst>
          <changeLogFile>${upgrade.0.23.0.changelog}</changeLogFile>
          <driver>com.mysql.jdbc.Driver</driver>
          <url>${liquibase.mysql.url}</url>
          <username>${liquibase.mysql.username}</username>
          <password>${liquibase.mysql.password}</password>
          <migrationSqlOutputFile>${database.script.directory}/mysql-upgrade-
          to-0.23.0.sql</migrationSqlOutputFile>
        </configuration>
      </execution>

      <execution>
        <id>generate-mysql-1.1.0-script</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>updateSQL</goal>
        </goals>
        <configuration>
          <dropFirst>false</dropFirst>
          <changeLogFile>${upgrade.1.1.0.changelog}</changeLogFile>
          <driver>com.mysql.jdbc.Driver</driver>
          <url>${liquibase.mysql.url}</url>
          <username>${liquibase.mysql.username}</username>
          <password>${liquibase.mysql.password}</password>
          <migrationSqlOutputFile>${database.script.directory}/mysql-upgrade-
           to-1.1.0.sql</migrationSqlOutputFile>
        </configuration>
      </execution>

      <execution>
        <id>generate-mysql-1.1.1-script</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>updateSQL</goal>
        </goals>
        <configuration>
          <dropFirst>false</dropFirst>
          <changeLogFile>${upgrade.1.1.1.changelog}</changeLogFile>
          <driver>com.mysql.jdbc.Driver</driver>
          <url>${liquibase.mysql.url}</url>
          <username>${liquibase.mysql.username}</username>
          <password>${liquibase.mysql.password}</password>
          <migrationSqlOutputFile>${database.script.directory}/mysql-upgrade- 

           to-1.1.1.sql</migrationSqlOutputFile>
        </configuration>
      </execution>
      <execution>
        <id>generate-mysql-1.2.0-script</id>
        <phase>prepare-package</phase>
        <goals>
          <goal>updateSQL</goal>
        </goals>
        <configuration>
          <dropFirst>false</dropFirst>
          <changeLogFile>${upgrade.1.2.0.changelog}</changeLogFile>
          <driver>com.mysql.jdbc.Driver</driver>
          <url>${liquibase.mysql.url}</url>
          <username>${liquibase.mysql.username}</username>
          <password>${liquibase.mysql.password}</password>
          <migrationSqlOutputFile>${database.script.directory}/mysql-upgrade-
          to-${squashTmVersion}.sql</migrationSqlOutputFile>
        </configuration>
      </execution>
    </executions>
   </plugin>

3 个答案:

答案 0 :(得分:3)

您收到此错误,因为网址的值由maven属性提供,称为$ {liquibase.mysql.url}

您可以在pom中设置maven属性的值,如:

 <project>
    [...]
    <properties>
      <liquibase.mysql.url>jdbc:mysql://127.0.0.1:3306</liquibase.mysql.url>
      <liquibase.mysql.username>someuser</liquibase.mysql.username>
      [...]
    </properties>
    [...]

liquibase插件还提供了从属性文件读取配置属性的可能性,例如SRC /主/资源/ liquibase.properties 如果你选择这个,你需要通过替换pom中的conofiguration部分来配置liquibase maven插件,如:

[...]
 <configuration>
    <propertyFile>src/main/resources/liquibase.properties</propertyFile>
 </configuration>
[...]

然后liquibase属性看起来应该是

url=jdbc:mysql://127.0.0.1:3306      
username=someuser
dropFirst=true
changeLogFile=yourfile
[...]

更多信息请点击此处:http://www.liquibase.org/documentation/maven/index.html#using_configuration_property_files

答案 1 :(得分:1)

您需要在.m2 / settings.xml中设置变量$ {liquabase.mysql.url}等。更多详情:Missing maven .m2 folder

您还需要运行mvn liquibase:update

答案 2 :(得分:0)

首先,您正在使用阶段进程资源,当您想要从输出目标目录处理changeLog时,以及如果您尝试使用maven资源过滤在资源文件中使用过滤时,基本上会使用阶段进程资源插件。

我不知道你实际上是在多少次使用prepare-package或任何这样的阶段,而且liquibase的maven没有像这样设置,你应该有一个主更新日志,其应该包括你的其他升级,在每次升级中都会进行一些预先检查。

如果您想使用流程资源阶段,并且打算在资源文件中进行某种过滤,那么您的目录结构应该类似于以下内容。

src/
`-- main
    |-- java
    `-- resources
        |-- changelog-1.0.0.xml
        |-- changelog-1.1.0.xml
        |-- changelog-install.xml
        |-- com
        |   `-- obolus
        |       `-- database
        |           `-- changelog
        |               |-- v000
        |               |   |-- cst
        |               |   |   |-- entity_extra_data.xml
        |               |   |   `-- entity.xml
        |               |   |-- master.xml
        |               |   `-- tab
        |               |       |-- company.xml
        |               |       |-- entity_extra_data.xml
        |               |       |-- entity.xml
        |               |       `-- anothertable.xml
        |               `-- v001
        |                   |-- master.xml
        |                   `-- tab
        |                       `-- sample.xml
        |-- lib
        |   |-- ojdbc6-11.2.0.3.jar
        `-- liquibase.properties

POM文件的示例

<?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.obolus</groupId>
    <artifactId>database</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>${liquibase.maven.plugin}</version>
                <configuration>
                    <changeLogFile>target/classes/changelog-install.xml</changeLogFile
                    <propertyFile>target/classes/liquibase.properties</propertyFile>
                    <logging>${logLevel}</logging>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>status</goal>
                        </goals>
                    </execution>
                </executions>            
            </plugin>
        </plugins>
        <!-- resource filtering -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
    <dependencies>
        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>${ojdbc.driver.version}</version>
        </dependency>
    </dependencies>
    <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>
        <ojdbc.driver.version>11.2.0.3</ojdbc.driver.version>
        <liquibase.maven.plugin>3.3.2</liquibase.maven.plugin>
        <logLevel>severe</logLevel>
    </properties>
</project>

希望有所帮助。