简体   繁体   中英

Maven resource filtering not replacing property

Here's my properties file:

version = ${maven.build.timestamp}

Here's how my pom.xml file looks like:

<properties>
    <maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<build>
    <plugins>
    ...
    </plugins>
    <resources>
        <resource>
            <directory>${project.basedir}/src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

And here's how my directory structure looks like:

.
├── pom.xml
├── src
│   └── main
│       ├── java
│       │   └── ...
│       ├── resources
│       │   └── application.properties

But when I do a mvn clean install and open up the target/classes/application.properties file, the contents of it is still the same: version = ${maven.build.timestamp}

Why isn't the property being properly replaced?

It's a known issue in Maven ( see here ). Simplest workaround is to redefine this property in your POM:

<properties>
    <maven.build.timestamp>${maven.build.timestamp}</maven.build.timestamp>
</properties>

Although this could generate an error in IDE like Eclpise it's still working as a maven build. Alternatively you could redefine this property with your own name to avoid IDE warnings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM