Spring Boot v2.1.3.RELEASE

I have an application.yml where I want to include profiles based on logical conditions on what profiles are active. I've attached my application.yml

---
spring.profiles: a & b
spring:
  profiles:
    include:
      - includeAandB
mypropAandB: valueAandB

---
spring.profiles: a
spring:
  profiles:
    include:
      - includeA
mypropA: valueA
---
spring.profiles: b
spring:
  profiles:
    include:
      - includeB
mypropB: valueB

---
spring.profiles: c
spring:
  profiles:
    include:
      - includeC
mypropC: valueC

When I run

SPRING_PROFILES_ACTIVE=a,b ./gradlew bootRun

I get

The following profiles are active: a,includeA,b,includeB

This seems inconsistent, I was expecting a,includeA,b,includeB,includeAandB or possible a,b if the includes were not supported.

Comment From: mbhave

Profile expressions (and negated profiles) get processed last, i.e. once we already know the profiles activated and included by the config files. If the YAML document that's activated by a profile expression itself contains a spring.profiles.include, that doesn't get processed at the moment.

We'd have to go over the config files again to look for documents matching the profiles included by the expression. Let's see if the rest of the team thinks this is something we should fix.

Comment From: mbhave

Based on the complexity of the fix we can decide whether it should go in 2.1.x or 2.2.x.

Comment From: mbhave

I have a fix for this here but this is turning out to get a bit complicated because of the way included profiles are supposed to be ordered. For example, look at the configuration below:

spring.profiles: a
spring.profiles.include: c
---
spring.profiles: a & b
spring.profiles.include: d,e
---
spring.profiles: d
spring.profiles.include: f
---

Given that profiles a and b are active, the above configuration will lead to a profile order of a, c, b, d, e, f, whereas one might expect it to be a, c, b, d, f, e. There are a lot of corner cases when it comes to profiles specific files/YAML documents and include profiles. We need to take a step back and redefine the rules, which will lead to a possible overhaul of this part of the code. We can tackle this in 2.3.x once we have a better idea of what it should look like.

Comment From: philwebb

Spring Boot 2.4 has overhauled config processing. See this blog post for details. Since the spring.profiles.include property won't be supported going forward you'll need to find a different way to do what you want.

I would suggest using @Profile("a & b") directly in your code or adding an EnvironmentPostProcessor to set new profiles based on the existing ones.

I'm going to close this one for now, but if you find there's an obvious use-case that we're missing from the new code then please comment back here and we can have another look. We'll need a bit more background about what's driving the need for the includeAandB profile in the first place.