javamavenmaven-antrun-plugin

use maven project information in resource files


I have directory structure like

.
├── pom.xml
└── src
    └── main
        ├── java
        │   └──
        └── resources
            └── plugin.yml

Of course in the pom.xml itself I can get the project version using ${project.version}, but I wonder if there's a way to inject this number into the plugin.yml file, its contents are:

name: PluginName
version: ${project.version}
description: Does plugin things

Is there a way to get maven to fill the version: value with the actual version of the project when it's built?


Solution

  • Check first if the filtering capabilities of maven are enough.
    See "Apache Maven Resources Plugin/ Filtering"

    Inside of <build> add

    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
          <include>plugin.yml</include>
        </includes>
      </resource>
    </resources>
    

    Then you can use ${...} variables in the src/main/resources/plugin.yml file.