在多模块 Maven 项目中使用 @project.version@ ​​和 Liquibase

bor*_*ter 6 java liquibase maven

想出一个有意义的标题有点困难,希望解释后它会变得足够清楚。我在 SO 上搜索了许多 Q 和 As,它们都非常接近我遇到的问题,但仍然不够接近。

一般来说,我想要完成的是通过@project.version@.csvLiquibase 脚本加载的文件访问 maven 属性来将项目版本存储在 DB 中。我的 Maven 项目结构如下所示:

parentModule
pom.xml
|
---moduleA
   |__pom.xml
---moduleB
   |__pom.xml
---moduleC
   |__pom.xml
...
Run Code Online (Sandbox Code Playgroud)

Pom.xml 定义为:

**PARENT POM**
<project ...>

  <groupId>com.parent</groupId>
  <artifactId>parent</artifactId>
  <version>1.0</version>
  <packaging>pom</packaging>
  <name>parent</name>

    <parent>
        <artifactId>spring-boot-starter-parent</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>2.2.1.RELEASE</version>
        <relativePath />
    </parent>

    <properties>
         <java.version>8</java.version>
    </properties>


    <modules>
        <module>moduleA</module>
        <module>moduleB</module>
        <module>moduleC</module>
        ...
  </modules>

  <build>
        <defaultGoal>package</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
----------------------------------------------------------------------

**CHILD POM**
<project ...>
    <artifactId>moduleC</artifactId>
    <name>moduleC</name>

    <parent>
        <groupId>com.parent</groupId>
        <artifactId>parent</artifactId>
        <version>1.0</version>
    </parent>

<dependencies>
    <dependency>
      ...
    </dependency>
</dependencies>
 <build>
   <resources>
        <resource>
            <directory>moduleC/src/main/resources/db/changelog/</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/app_version.csv/</include>
            </includes>
        </resource>
    </resources>
 </build>
</project>
Run Code Online (Sandbox Code Playgroud)

Liquibase 脚本在moduleC/src/main/resources/db/changelog/changelog-master.xmletc.中定义,而具有初始值的 .csv 文件位于moduleC/src/main/resources/db/users.csvetc. 在这些 csv 文件之一中,我想推送@project.version@值,如下所示:

id;app_key;app_value;created_by;last_modified_by
1;app-version;@project.version@;system;system
Run Code Online (Sandbox Code Playgroud)

由于该文件位于 中moduleC,我什parentModule <build/>至使用了 Maven 资源过滤来过滤该文件,以便它可以解析@project.version@属性,但没有运气:

<build>
    <resources>
        <resource>
            <directory>moduleC/src/main/resources/db/changelog/</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/app_version.csv/</include>
            </includes>
        </resource>
    </resources>
    <defaultGoal>package</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <skip>true</skip>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

有错误,一个说找不到主更改日志,而在其他情况下只@project.version@存储字符串值。在我看来,我应该在 parentModule pom.xml 中将app_version.csv其位置 ( moduleC) 作为资源包含在<build>标签内,但是每个引用它的组合都失败了。是否有正确引用它的解决方案(来自 parentModule 或 moduleC pom.xml),或者可能有更简单的方法来存储@project.version@liquibase?

bor*_*ter 2

我非常抱歉没有及时回复,在发布问题后被暂时从项目中删除,并且由于位置更改而无法访问 git 存储库。到目前为止,我已尝试了所有建议的操作,但没有结果。最后,我发现有效的是这里发布的已接受的答案。我已经在 mavenC 模块 pom.xml 中添加了构建块并且它起作用了。尽管如此,非常感谢大家的发帖和帮助。