liquibase / liquibase-groovy-dsl

The official Groovy DSL for Liquibase
Other
83 stars 34 forks source link

Cannot configure plugin with maven #23

Closed nicolasgnr closed 8 years ago

nicolasgnr commented 8 years ago

I'm having a problem when executing the update goal. I get the following error:

[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.1:update (default) on project liquibase-sample-mvn: Error setting up or running Liquibase: Cannot find parser that supports src/main/resources/liquibase/masterChangelog.groovy -> [Help 1]

For some reason the GroovyLiquibaseChangeLogParser is not been registered in the ChangeLogParserFactory. When I inspect the parsers a cannot see the groovy one.

Here is my 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.liquibase-sample</groupId>
    <artifactId>liquibase-sample-mvn</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>Liquibase sample mvn</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>

        <!-- Database -->
        <postgres.version>9.1-901-1.jdbc4</postgres.version>
        <dbh2.version>1.4.192</dbh2.version>
        <liquibase.version>3.5.1</liquibase.version>
        <liquibase-groovy.version>1.2.1</liquibase-groovy.version>
    </properties>

    <dependencies>
        <!-- Database -->
        <dependency>
            <groupId>postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>${postgres.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>${dbh2.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-groovy-dsl</artifactId>
            <version>${liquibase-groovy.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.liquibase</groupId>
                <artifactId>liquibase-maven-plugin</artifactId>
                <version>${liquibase.version}</version>
                <configuration>
                    <propertyFile>db.properties</propertyFile>
                </configuration>
                <executions>
                    <execution>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>update</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Any ideas?

stevesaliman commented 8 years ago

I'm not a Maven expert, but my guess is that the problem is related to the classpath. The liquibase-groovy-dsl does not need to be in the classpath of the project, but it does need to be in the classpath of the build.

In Gradle, there is a difference between the classpath used for calculating project dependencies/generating project POMS, and the classpath used by gradle itself when executing tasks. I'm betting that Maven has the same.

In your case, declaring the dependency where you have tells Maven that it needs liquibase-groovy-dsl to compile the project (it doesn't), but it probably doesn't tell maven that it needs to be in the classpath when it executes the liquibase-maven-plugin.

You can probably fix the problem by telling Maven to include liquibase-groovy-dsl in its own classpath when it executes plugins. Probably somewhere in the <build> or <plugins> sections.

Sorry I couldn't be more specific.

nicolasgnr commented 8 years ago

Hi! Thanks for the answer. I've resolved the problem by adding the dependency to the specific plugin such like this:

<plugin>
    <groupId>org.liquibase</groupId>
    <artifactId>liquibase-maven-plugin</artifactId>
    <version>${liquibase.version}</version>
    <configuration>
        <changeLogFile>src/main/resources/liquibase/masterChangelog.groovy</changeLogFile>
        <propertyFile>db.properties</propertyFile>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-groovy-dsl</artifactId>
            <version>${liquibase-groovy.version}</version>
        </dependency>
    </dependencies>
</plugin>
stevesaliman commented 8 years ago

Thank you for including the snippet from your pom file. It will help others who run into the same problem.