I think there're a couple of issues with the default configuration of the maven-resources-plugin within spring-boot-starter-parent; I'll be glad to contribute a pull request (I suppose it'll land in 1.2 since it might be a non-retrocompatible change) if you think this makes sense.
Proposed solution: use a different default configuration for maven-resources-plugin, limiting the compile-time filtering delimiter to '@', something like
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
- The default resources filtering in spring-boot-starter-parent only applies to _application.yml_ and _application.properties_. This can lead to unpredictable results when using profiles: application.properties would be filtered, while application-profile.properties would not.
Proposed solution: filter application-\* files as well.
- The documentation at [58.3](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-use-short-command-line-arguments) is a bit misleading, saying that
If you have enabled maven filtering for the application.properties you may want to avoid using ${*} for the tokens to filter as it conflicts with those placeholders. You can either use @*@ (i.e. @maven.token@ instead of ${maven.token}) or you can configure the maven-resources-plugin to use other delimiters.
The suggestion is fine (it's what I did in the implementation) but it would suggest that resources filtering is not enabled by default, while it is indeed.
Proposed solution: change the docs to reflect what actually happens when filtering.
Of course this whole issue could be solved by completely disabling resource filtering in spring-boot-starter-parent.
Let me know what you think about that.
My preference would be to remove the filtering configuration entirely, I think that's something that should be opt-in. @dsyer @wilkinsona any thoughts?
that would be my preference too.
I'm not a big fan of filtering resources. I think the main reason it is there though is to easily enable the /info endpoint to be wired up to report the maven co-ordinates of the app (in particular the version). I have found that extremely useful in the past, so much that I would even like it to be more of an opt out. Maybe we can do that without filtering in the resources plugin?
If my opinion can be useful, I'd say that, taking a look at the aim of spring-boot, a default configuration for resource filtering is a good thing to have, but it must be the proper configuration, not something that clashes with other pieces of the Spring Framework; hence my proposal.
The parent project spring-boot-starter-parent, as per doc, should provide "sensible resource filtering" - so I think that it's good to enable filtering. If somebody doesn't want any filtering in order to do everything manually, he can just remove the dependency on the parent project and include the pieces he wants to.
At our company we've got some parent poms which we use in a very similar fashion of spring-boot-starter-parent , and we like such project because we could just drop them and use spring-produced ones, which are good and well maintained. In our parent poms we employed filtering just like the configuration I proposed, and I must say it is extremely hard for filtering to be triggered inadvertently - if you need to filter anything, you'll have to do something like
[email protected]@
Which is unlinkely to clash with anything else. And using it to match the version, the build number (like @dsyer suggested), along with the changeset, is precisely what we do (with great joy).
Don't fear the filtering :-)
I guess whatever we do here will be a breaking change, and as I don't want to break existing info endpoints. I'll re-target this for 1.2 and create a new issue to fix the documentation for 1.1. The @some.value@ seems like the best compromise so far.
This ticket and the docs suggest that ${*} was disabled. It doesn't look to be the case. The maven-resources-plugin seems like it would have to also be configured with
<useDefaultDelimiters>false</useDefaultDelimiters>
Without that setting, it seems that the plugin is adding the default delimiters (${*} and '@) to the defined delimiters (@). (Not what I'd expect the plugin to do..)
@ericdahl It's not clear to me if you have found an actual problem or if you are talking theoretically. Note that Maven's docs state that the configuration we've used specifies the "default filtering delimiters". If you have found an actual problem then please open a new issue (this one is closed), with a sample that reproduced it.
@wilkinsona
It's more theoretical. The ${*} delimiter still works so nothing is broken. It seems that it was intended to be removed (this issue mentions "breaking change" in reference to removing it). I can dig deeper and create an issue this weekend.
As far as I can tell the configuration in the starter-parent pom.xml does nothing.
@wilkinsona
I was going to write up a issue for this but https://github.com/spring-projects/spring-boot/issues/3092 already exists for this issue.
There seems to be confusion about how the plugin works. The <useDefaultDelimiters>false</useDefaultDelimiters> is necessary to cause ${} to be disabled. Without this, maven is processing variables at build-time that I'd rather have evaluated at run-time by Spring's property evaluation.
I was wrong when I said it was a theoretical issue.
Im using with:
application-dev.yml
spring:
datasource:
dataSourceClassName: com.mysql.jdbc.jdbc2.optional.MysqlDataSource
url: jdbc:mysql://localhost:3306/balerocms_enterprise?useUnicode=yes&characterEncoding=UTF-8
databaseName:
serverName:
username: @db.user@
pom.xml
< properties >
< db.user>root</db.user >
< /properties >
Im using Java 8, and it says:
objc[1577]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/bin/java and /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
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 7, column 19:
username: @db.user@
^
at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:420)
at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226)
at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586)
at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158)
at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143)
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132)
at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229)
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)
at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229)
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)
at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:229)
at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:155)
at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122)
at org.yaml.snakeyaml.composer.Composer.getNode(Composer.java:84)
at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:104)
at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:471)
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:161)
at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:139)
at org.springframework.boot.env.YamlPropertySourceLoader$Processor.process(YamlPropertySourceLoader.java:100)
at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:57)
at org.springframework.boot.env.PropertySourcesLoader.load(PropertySourcesLoader.java:126)
at org.springframework.boot.context.config.ConfigFileEnvironmentPostProcessor$Loader.loadIntoGroup(ConfigFileEnvironmentPostProcessor.java:361)
at org.springframework.boot.context.config.ConfigFileEnvironmentPostProcessor$Loader.load(ConfigFileEnvironmentPostProcessor.java:339)
at org.springframework.boot.context.config.ConfigFileEnvironmentPostProcessor$Loader.load(ConfigFileEnvironmentPostProcessor.java:318)
at org.springframework.boot.context.config.ConfigFileEnvironmentPostProcessor.addPropertySources(ConfigFileEnvironmentPostProcessor.java:145)
at org.springframework.boot.context.config.ConfigFileEnvironmentPostProcessor.postProcessEnvironment(ConfigFileEnvironmentPostProcessor.java:125)
at org.springframework.boot.env.EnvironmentPostProcessingApplicationListener.onApplicationEvent(EnvironmentPostProcessingApplicationListener.java:51)
at org.springframework.boot.env.EnvironmentPostProcessingApplicationListener.onApplicationEvent(EnvironmentPostProcessingApplicationListener.java:40)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:163)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:136)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:119)
at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111)
at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:65)
at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
at org.springframework.boot.SpringApplication.doRun(SpringApplication.java:307)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:273)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:971)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:960)
at com.neblina.balero.Application.main(Application.java:27)
Any comments?
@neblina-software This issue's closed and you haven't provided enough information to diagnose the problem. If you believe you have found a bug please open a new issue describing the version of Spring Boot, Maven etc that you're using and how to recreate the problem.
@neblina-software try setting <addResources>false</addResoruces> for the spring-boot-maven-plugin. See the hint in http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#production-ready-application-info-automatic-expansion
I think its a bug, im going to create the issue.
The problem is, spring boot it's not creating and copying *.properties files to target/ folder.
It only create when execute:
$ mvn test
and not when executing:
$ mvn spring-boot:run -P prod
i'm using:
https://github.com/neblina-software/balerocms-enterprise
Note: Using YAML format will be display a stack trace.
Testing copy resources:
/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bin/java "-Dmaven.home=/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 14.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.4.jar:/Applications/IntelliJ IDEA 14.app/Contents/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=14.1.5 org.apache.maven.plugins:maven-resources-plugin:2.6:copy-resources -P prod,dev
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building balero 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:copy-resources (default-cli) @ balero ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.151s
[INFO] Finished at: Mon Oct 26 11:16:35 CST 2015
[INFO] Final Memory: 6M/77M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:copy-resources (default-cli) on project balero: The parameters 'resources', 'outputDirectory' for goal org.apache.maven.plugins:maven-resources-plugin:2.6:copy-resources are missing or invalid -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
'outputDirectory' is missing.
Note: Looks like this issue appears in Java 8, im using Java 8.
Most helpful comment
Im using with:
pom.xml
Im using Java 8, and it says:
Any comments?