Spring - Profie in external dependency

121 views Asked by At

In wrote dependency which has diffrent profiles (actually it's maven profiles) and I include it into my project. How can I select with which profile from this dependency my project should be build using property in some properties file e.g:

spring.profileinmydepedency = prod

Can you show my some examples , how to do it in spring (not boot) ?

1

There are 1 answers

2
hovanessyan On

You can't.

Having different maven profiles for a maven module means that building that project with a specific profile, will produce a specific build - maven artefact.

In your Spring's project (which is also a maven project) pom.xml file, you declare the dependency on the already build maven artefact.

There's no way in Spring in which you define a property and it binds a binary file pre-build with that profile to your application.

The most straight forward approach you can go for is duplicate the profiles from your dependency in your Spring project.

For example if your dependency has profiles P1 and P2 and the build artefacts are dep-p1 and dep-p2 respectively, in your Spring's pom.xml you will have:

<profiles>
    <profile>
        <id>spring-p1</id>
        …
        <dependencies>
            <dependency>dep-p1</dependency>
        </dependencies>
        …
    </profile>
    <profile>
        <id>spring-p2</id>
        …
        <dependencies>
            <dependency>dep-p2</dependency>
        </dependencies>
        …
    </profile>
</profiles>

Then when you build your project with spring-p1 profile, it will include the dep-p1 dependency.