sts4 icon indicating copy to clipboard operation
sts4 copied to clipboard

application.properties in main and test source folder

Open renetrefft opened this issue 6 years ago • 4 comments

An application.properties file is stored in src/main/resources as well as in src/test/resources defining the same property with a different value. Further a JUnit test exists which prints the value of that property (assigned to a variable using the Value annotation).

If the JUnit test is called by Run As -> JUnit Test the value of the main application.properties is printed. Instead, if the test is called with "gradlew clean test", the value of the test application.properties is printed.

If an application.properties/yml (or bootstrap.properties/yml if Spring Cloud Config is used) file exists both in main and test source folder, always and only the latter file should be resolved for a JUnit test.

Tested with Eclipse 4.10.0, Spring Tools 4.3.0, Gradle 4.10.3 and Spring Boot 1.5.21.

As a workaround src/test/resources/application.properties can be moved to src/test/resources/config/application.properties to print the value of the test application.properties. But then other properties from the main application.properties are also available, i.e. test application.properties does not replace main application.properties.

renetrefft avatar Jul 08 '19 15:07 renetrefft

(comment in Pivotal Tracker added by Alex Boyko:)

This should begin to work starting Gradle 5.6.0. Current latest is 5.5.1. See https://github.com/eclipse/buildship/issues/689 @krisde I suppose we should keep this one opened until Gradle 5.6.0 is out and we can test this use case with Buildship?

spring-projects-issues avatar Jul 18 '19 17:07 spring-projects-issues

(comment in Pivotal Tracker added by Kris De Volder:)

I suppose we should keep this one opened until Gradle 5.6.0 is out and ...

Yes, that sounds like a good idea. We can move this ticket further down the backlog for now, since there's not much we can do at the moment except wait to confirm the fix.

spring-projects-issues avatar Jul 18 '19 17:07 spring-projects-issues

Issue still exists. Tested with Eclipse 2022-12, STS 4.17.1, Spring Boot 3.0.1 and Gradle 7.6.

BTW: It works correctly on IntelliJ IDEA, also if test is executed with IDEA runner.

renetrefft avatar Jan 17 '23 19:01 renetrefft

This is a Buildship issue. I've raised https://github.com/eclipse/buildship/issues/1221

BoykoAlex avatar Jan 18 '23 23:01 BoykoAlex