【问题标题】:Proguard breaks Flyway database migrationProguard 打破 Flyway 数据库迁移
【发布时间】:2017-09-06 03:02:00
【问题描述】:

发布这个自我回答,所以当我在几个月后再次打破它时,实际上会在谷歌中找到答案。

使用 Flyway API 迁移数据库模式的简单 Java 项目。遵循 V1__init.sql、V2__updateCustomerTable.sql 约定的 sql 脚本资源目录用于检查 schema_version 元数据表并在需要时进行迁移。

在 jar 被保护之前一切正常。 sql脚本肯定是打包进jar文件的,但是找不到:

2017-04-10 17:17:13,612 [main] DEBUG (?:?) - Validating migrations ...
2017-04-10 17:17:13,884 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: '', Suffix: '.sql')
2017-04-10 17:17:13,885 [main] DEBUG (?:?) - Determining location urls for classpath:db/migration/postgres using ClassLoader sun.misc.Launcher$AppClassLoader@8b819f ...
2017-04-10 17:17:13,885 [main] WARN  (?:?) - Unable to resolve location classpath:db/migration/postgres
2017-04-10 17:17:13,899 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'V', Suffix: '.sql')
2017-04-10 17:17:13,900 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'R', Suffix: '.sql')

一个未经保护的 jar 使用以下日志消息找到它们(注意它现在在 jar 文件中查找):

2017-04-10 17:07:16,612 [main] DEBUG (?:?) - Validating migrations ...
2017-04-10 17:07:16,613 [main] DEBUG (?:?) - Scanning for classpath resources at 'classpath:db/migration/postgres' (Prefix: 'V', Suffix: '.sql')
2017-04-10 17:07:16,614 [main] DEBUG (?:?) - Scanning URL: jar:file:/C:/Dev/Sanbox/myjar.jar!/db/migration/postgres
2017-04-10 17:07:16,614 [main] DEBUG (?:?) - JBoss VFS v2 available: false
2017-04-10 17:07:16,615 [main] DEBUG (?:?) - Filtering out resource: db/migration/postgres/ (filename: )
2017-04-10 17:07:16,615 [main] DEBUG (?:?) - Found resource: db/migration/postgres/V1__init.sql
2017-04-10 17:07:16,616 [main] DEBUG (?:?) - Found resource: db/migration/postgres/V2__updateCustomerTable.sql

【问题讨论】:

    标签: java maven proguard flyway


    【解决方案1】:

    罪魁祸首是你需要告诉 proguard 将你的 db/migrations 目录单独留在你的配置文件中(或者你放置迁移脚本的任何地方),否则即使它们看起来是 flyway 也无法找到你的脚本在罐子的正确位置。这是我在 proguard 配置中需要的行:

    -keepdirectories db/migration/**
    

    如果您更改了放置 sql 脚本的位置,则此配置也需要更新。

    【讨论】:

    • 我必须在“db”、“db/migration”和“db/migration/**”上添加keepdirectories,然后才能工作,但现在可以工作了。 (非常感谢!)
    猜你喜欢
    • 2017-07-10
    • 2013-03-06
    • 2014-08-02
    • 2015-02-17
    • 2015-12-19
    • 2018-11-26
    • 1970-01-01
    • 2017-10-30
    • 2015-05-04
    相关资源
    最近更新 更多