在构建时获取Maven属性 [英] Get maven properties at build time

查看:46
本文介绍了在构建时获取Maven属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于pom.xml获取一些属性="nofollow">文档.

I'm trying to get some properties from the pom.xml at build time based on the documentation.

我的目标是将它们注入到我的Spring boot application.properties中,但是属性不会被替换.

My goal is to inject them in my Spring boot application.properties but the properties are not replaced.

这是我的代码

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>xx</groupId>
    <artifactId>xx</artifactId>
    <packaging>jar</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>xx</name>

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

<dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <type>jar</type>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <scope>test</scope>
    </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-tomcat</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-jetty</artifactId>
            </dependency>
</dependencies>

<build>
        <finalName>xx</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins> 
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>static</directory>
                <targetPath>static</targetPath>
            </resource>
        </resources> 
</build>

src \ main \ resources \ application.properties

application.version=${project.version}

我错过了什么吗?这应该起作用吗?

Am I missing something? Is this supposed to work?

推荐答案

如果您使用的是spring boot父pom,则将默认占位符重新配置为不与spring本身的$ {}语法冲突.

If you are using the spring boot parent pom the default placeholders have been re-configured to not conflict with the ${} syntax of spring itself.

要替换Maven属性,请使用@-以便@ project.version @而不是$ {project.version}.

To replace the maven properties use @ - so @project.version@ instead of ${project.version}.

默认情况下启用对application.properties文件的过滤.

filtering of the application.properties file is enabled by default.

这篇关于在构建时获取Maven属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆