"Incorrect syntax near 'GO'" exception in MS SQL 2016 with Liquibase 4.16.1 community and JDBC driver

I am trying to implement the CI/CD process with Teamcity. I have Liquibase 4.16.1 with JDBC driver and MS SQL 2016 as the target database. Liquibase is running on Teamcity Linux agent installed on RHEL 7.
I add the following liquibase header to my .sql file

--liquibase formatted sql
--changeset mycompany:1 **endDelimiter:\nGO** stripComments:false runonchange:true

The .sql file contains several GO lines after USE, SET, IF, ALTER PROCEDURE, and GRANT statements.
Most of the files with the same structure work well, but there are several files that fail with error:

SEVERE [liquibase.integration] Migration failed for changeset ... :
**Reason: liquibase.exception.DatabaseException: Incorrect syntax near 'GO'.** [Failed SQL: (102) /*

some comments…

ALTER PROCEDURE [dbo].My_Procedure
   @ResultMSG varchar(255) = NULL output

begin tran
commit tran

GRANT EXECUTE ON dbo.My_Procedure TO [domain\MyUsers] AS dbo
   at liquibase.command.CommandScope.execute(CommandScope.java:179)
   at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:51)
   at liquibase.integration.commandline.CommandRunner.call(CommandRunner.java:21)
   at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
   at picocli.CommandLine.access$1300(CommandLine.java:145)
   at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2358)
   at picocli.CommandLine$RunLast.handle(CommandLine.java:2352)
   at picocli.CommandLine$RunLast.handle(CommandLine.java:2314)
   at picocli.CommandLine$AbstractParseLastResultHandler.execute(CommandLine.java:2179)
   at picocli.CommandLine$RunLast.execute(CommandLine.java:2316)
   at picocli.CommandLine.execute(CommandLine.java:2078)
   at liquibase.integration.commandline.LiquibaseCommandLine.lambda$execute$1(LiquibaseCommandLine.java:353)
   at liquibase.Scope.child(Scope.java:189)
   at liquibase.Scope.child(Scope.java:165)
   at liquibase.integration.commandline.LiquibaseCommandLine.execute(LiquibaseCommandLine.java:318)
   at liquibase.integration.commandline.LiquibaseCommandLine.main(LiquibaseCommandLine.java:84)
   at java.base/jdk.integration.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at java.base/jdk.integration.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at java.base/jdk.integration.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.base/java.lang.reflect.Method.invoke(Method.java:566)
   at liquibase.integration.commandLine.LiquibaseLauncher.main(LiquibaseLauncher.java:107)

I started SQL Profiler and I see that this part of .sql file was not split by GO. I.e. the statements that passed to SQL Server contain GO lines. The previous parts of the same file were successfully split and executed as separate parts by SQL Server.
So, it looks like the problem is in splitting the original file by GO.
I verified that all GO statements are exactly the same:

  • They located at separate line as first characters of the line.
  • The characters are the same (47, 4F)
  • Before and after GO there are the same characters 0A
  • The .sql file is in UTF-8

When I remove last 3 lines this changeset works without any issues:
GRANT EXECUTE ON dbo.My_Procedure TO [domain\MyUsers] AS dbo

Any idea how to avoid the issue?

It looks like this is the issue described here:

1 Like