Chris Savory
Chris Savory

Reputation: 2755

Spring Boot property expansion not working after switching from Eclipse to IntelliJ

Our app has for properties that we pick up dynamically from the Maven project files.

info:
  build:
    artifact: @project.artifactId@
    name: @project.name@
    description: @project.description@
    version: @project.version@

http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#production-ready-application-info-automatic-expansion-maven

When we were using Eclipse these were not a problem, but now on moving to InelliJ the app won't startup unless I provide some hardcoded values for those dynamic properties.

I get this error:

19:47:20.962 [main] INFO  com.edlogics.ElrcApplication - Spring Boot configuration: profiles = [local, chris]
19:47:20.968 [main] INFO  com.edlogics.ElrcApplication - Spring Boot configuration: properties = {}
Exception in thread "main" while scanning for the next token
found character '@' that cannot start any token. (Do not use @ for indentation)
 in 'reader', line 74, column 11:
        name: @project.name@
              ^

 org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:420)
 org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226)
 org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586)
 org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
 org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143)
 org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132)
 org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229)
 org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)
 org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229)
 org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)
 org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229)
 org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)
 org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122)
...

Process finished with exit code 1

I realize that @ is not a valid YAML character, just not sure how this was working in Eclipse and not in IntelliJ

Edit:

One thing that I left out of the original questions is that we have a multi-module project. It's the project's root pom that inherits from spring-boot-starter-parent that has this:

        <resources>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/application.yml</include>
                <include>**/application.properties</include>
            </includes>
        </resource>
        <resource>
            <directory>${basedir}/src/main/resources</directory>
            <excludes>
                <exclude>**/application.yml</exclude>
                <exclude>**/application.properties</exclude>
            </excludes>
        </resource>
    </resources>

And in our project it is a submodule that is in need of the filtering. The application.yml file is in the correct location of the submodule and Eclipse did not seem to mind that it was a submodule. I know that Eclipse and IntelliJ treat multi-module projects a little differently (Eclipse has flat structure while IntelliJ is hierarchical).

Upvotes: 15

Views: 24381

Answers (6)

Bogdan Pop
Bogdan Pop

Reputation: 103

Right click on pom.xml -> maven -> reload project and Build -> rebuild project helped me with this issue.

Upvotes: 1

Praveen Raghav
Praveen Raghav

Reputation: 39

        <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>

Adding above in pom.xml tag fixed the issue.

https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

Upvotes: 2

Mukit09
Mukit09

Reputation: 3399

It worked for me:

artifact: '@project.artifactId@'

Just kept the value within single quotes

Upvotes: 9

Fox user9219598
Fox user9219598

Reputation: 111

Adding quotes solves ? from artifact: @project.artifactId@ to => 'artifact: @project.artifactId@'

Upvotes: 0

Chris Savory
Chris Savory

Reputation: 2755

Turns out that the resource filtering was working in IntelliJ. There was one property, @project.name@ out of the four that was not being filtered correctly. Somehow this wasn't a problem in Eclipse. So we just removed that property from application.yml since we weren't using it.

Also, right-clicking on the pom.xml and selecting Maven then reimport seems to help with this. This especially helps if IntelliJ does not currently recognize yoru project as a Maven project. enter image description here

Upvotes: 27

Anton Fifindik
Anton Fifindik

Reputation: 11

Update intellij idea (to 2018.1.7 (build 181.5540.23)) helped in my case!

Upvotes: 0

Related Questions