liquibase / liquibase-gradle-plugin

A Gradle plugin for Liquibase
Other
199 stars 59 forks source link

Task "updateSQL" ignores "--outputFile" parameter #139

Closed ChristianHuff-DEV closed 7 months ago

ChristianHuff-DEV commented 8 months ago

I'm trying to write a Gradle task that takes in a changeLogFile and creates a Microsoft SQL compatible script.

The problem is that the parameter --outputFile is seemingly being ignored. The task itself finishes successful but no file is created. If I run the task without the parameter the SQL is printed to the console.

It appears this has been already a problem in the past. (See https://github.com/liquibase/liquibase-gradle-plugin/issues/90.)

Here is the (reduced) build.gradle I'm using. (I created an example Project to reproduce the issue.) The project is using Liquibase 4.24.0 (Spring Boot 3.2.2).

plugins {
    id 'org.liquibase.gradle' version '2.2.1'
}

dependencies {
    liquibaseRuntime 'org.liquibase.liquibase-core:4.24.0'
    liquibaseRuntime 'info.picocli:picocli:4.7.5'
}

tasks.register("generateSQL", JavaExec) {
    group = 'liquibase'
    classpath = sourceSets.main.runtimeClasspath
    mainClass = 'liquibase.integration.commandline.Main'

    def changeLogFile = 'src/main/resources/db/changelog/db.changelog-master.yaml'
    def outputFile = 'src/main/resources/db/changelog/db.changelog-master.sql'

    args '--changeLogFile=' + changeLogFile
    args '--url=offline:mssql'
    args '--outputFile=' + outputFile
    args 'updateSql'
}

This is a simplified example. In the real application I have a folder that contains multiple change log files (one for each version of the application). A Gradle task iterates over the change log files and generates the SQL script. This way I have one SQL script for each version.

Using the Liquibase CLI directly (https://hub.docker.com/r/liquibase/liquibase) the parameter is taken into account and the file created.

stevesaliman commented 8 months ago

Is the issue with the generateSQL task?

If so, then this isn't a gradle plugin issue because your task doesn't use the plugin - it calls Liquibase directly.

You said that there was no file, but that when you left out the output file, it gave you SQL on the console. That makes me wonder if the SQL script is being generated, just in a different location. I don't know why it works differently calling liquibase from the CLI vs a JavaExec. The only things I can think of is argument order or classpath differences.

ChristianHuff-DEV commented 8 months ago

Yes, the issue is the generateSQL task.

I searched the whole hard drive but couldn't find the generated file anywhere.

Since it works when I'm using the CLI I assumed it should also work when calling it directly. Furthermore when I change the parameter name to something other than --outputFile (i.e. --output-file), an error occurs. So it appears to be parsed successfully but then discarded.

SEVERE: Unexpected error running Liquibase: Unknown option: 'output-file'
liquibase.exception.CommandLineParsingException: Unknown option: 'output-file'
    at liquibase.integration.commandline.Main.parseOptionArgument(Main.java:1268)
    at liquibase.integration.commandline.Main.parseOptions(Main.java:1180)
    at liquibase.integration.commandline.Main$1.run(Main.java:284)
    at liquibase.integration.commandline.Main$1.run(Main.java:230)
    at liquibase.Scope.child(Scope.java:193)
    at liquibase.Scope.child(Scope.java:169)
    at liquibase.integration.commandline.Main.run(Main.java:230)
    at liquibase.integration.commandline.Main.main(Main.java:166)
ChristianHuff-DEV commented 7 months ago

I switched to using the Docker image.