Maven 使用profiles 時 值沒法替換問題

問題背景:爲了方便管理多個環境,maven中提供profilesspring

以下 :apache

目錄結構:json

pom.xmlapp

<profiles>
        <profile>
            <id>dev</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <profile.env>application-dev</profile.env>
            </properties>
        </profile>
        <profile>
            <id>produce</id>
            <properties>
                <profile.env>application-produce</profile.env>
            </properties>
        </profile>
    </profiles>
<build>
        <filters>
            <filter>${project.basedir}/profiles/${profile.env}.properties</filter>
        </filters>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <!-- Support our own plugin -->
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <skipTests>true</skipTests>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <useDefaultDelimiters>true</useDefaultDelimiters>
                    <delimiters>
                        <delimiter>$[*]</delimiter>
                    </delimiters>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
    </build>

application.properties 中使用 ${} 取值,老是取不到,最終使用 mvn package -X 跟蹤到 竟然有分隔符jvm

最終將分隔符,修改成$[*] 後 能夠正常取值。maven

經過spring-boot

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <configuration>
                    <useDefaultDelimiters>true</useDefaultDelimiters>
                    <delimiters>
                        <delimiter>$[*]</delimiter>
                    </delimiters>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>

maven-resource-plugin 配置 默認分隔符 delimiterui

相關文章
相關標籤/搜索