0

This is the build configuration of my project in pom.xml, When I pack the project, the property files already changed with the selected profile properties, but when I run the project using maven-boot-plugin:run in Intellij IDEA, the property files changed to old style and the database connection raises exception. for example the normal application.properties has the below key :

spring.datasource.url=${datasourceUrl}

and after packing the project it is :

spring.datasource.url=url1

but after running spring boot plugin the property files changed to the first style.

<profiles>
    <profile>
        <id>Live</id>
        <properties>
            <datasourceUrl>url1</datasourceUrl>
        </properties>
    </profile>

    <profile>
        <id>Test</id>
        <properties>
            <datasourceUrl>url2</datasourceUrl>
        </properties>
    </profile>
</profiles>


<build>
    <defaultGoal>install</defaultGoal>
    <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.*</include>

            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
            <executions>
                <execution>
                    <id>run</id>
                    <phase>package</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>

            <executions>
                <execution>
                    <id>repack</id>
                    <phase>package</phase>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>unpack</id>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>unpack</goal>
                    </goals>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                mywar 
                                <type>war</type>
                                <overWrite>false</overWrite>
                                <outputDirectory>${project.build.directory}/classes/static/</outputDirectory>
                                <includes>**/*</includes>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Pooya
  • 4,385
  • 6
  • 45
  • 73
  • and how do you pass the profile exactly? – Stephane Nicoll Feb 09 '16 at 07:08
  • @StéphaneNicoll By passing -P Live to maven – Pooya Feb 09 '16 at 08:28
  • Which version of Spring Boot are you using? In 1.2, the sources are added at the beginning of the classpath to allow live-editing of files. This prevent filtering and we considered this a bad default so we changed that in 1.3. [Reading the doc](http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-application-info-automatic-expansion) should help. If you're using 1.2, set `addResources` to `false` or upgrade to 1.3 – Stephane Nicoll Feb 09 '16 at 09:24
  • Unrelated: why do you run the plugin from IJ? Isn't it 100 times easier to run the main method? – Stephane Nicoll Feb 09 '16 at 09:26

0 Answers0