maven profiles or spring profiles?
Asked Answered
R

5

41

a lot java applications are build with maven. maven has Profiles concept, it is really handy to build release package for different environments. e.g. dev/test/prod using different path / jndiname / security rule / properties files... I think I don't have to list codes here to explain it.

Spring is a very nice and popular framework for java development, since spring3 it has supported profiles concept too.

Now question comes, for releasing to different ENVs purpose, which one is better? right now I prefer maven profile. since spring has to copy each bean definition in each profile. and it needs an initializer/property to let spring know which profile should be actived.

but I feel spring profile is more flexible than maven profile.

what do you think? please give some advices. thank you.

Respire answered 8/8, 2012 at 16:33 Comment(0)
L
43

Maven profiles would provide a build-time solution, while SpringFramework profiles would provide a runtime alternative. I think this is the first question one may ask himself: if he wants to have a single package that can be deployed in different environments, or if he wants the build tool to provide different packages according to the destination environment.

One thing to keep in mind is that many questions may arise if you have different packages deployed into different servers. In my workplace, for example, if I am deploying a package to correct a bug previously occurred in production environment, a company policy would state that the only acceptable scenario is that I have the same solution package in QA and in production servers.

Leger answered 8/8, 2012 at 16:51 Comment(0)
I
10

If you need different artifacts then go with maven. If it is just a real configuration that can be configured AFTER the artefact is build then user Spring profiles.

Ible answered 8/8, 2012 at 16:47 Comment(0)
U
7

As mentioned in the other replies: it all depends on how you work :)

What we came up with in the last years using maven and now the spring 3.1 profiles is this:

  • we use the maven-release-plugin to cut releases. this causes issues with environments if we would use maven profiles since we would need to rebuild the release or at least the tag with every maven profile
  • so we create on .war file for all environments and use the spring PropertyPlaceholderConfigurer to setup the application (or some JNDI resource depending on the customer). This allows to have only one maven release run.
  • the spring profiles come in when environments differ as well. for example an authentication service that is not available on all environments. Here we stub that service and put it into a spring profile. We active the spring profiles in the properties that is read by the PropertyPlaceholderConfigurer we use anyway.

there are some nice tutorials around on how to do that:

we usually only use maven profiles to split the build into different parts for the developers and the continuous integration build. We don't actually use them for target environments anymore for the .war files. We still use maven profiles for automated database deployments, which differ more compared to the web-apps (amount of data, test-data, ...), but these are not delivered as a zip or so.

There are surely other ways to go. I dont think its the end of the story :)

But it may help.

Unblinking answered 8/8, 2012 at 17:7 Comment(0)
H
2

I happened to use properties-maven-plugin to set a system property depending on which maven profile was activated. Then in Spring, I was activating programmatically the profile(s) that I wanted, depending on that system property :

String activeProfile = System.getProperty("myapp.profile");

appContext.getEnvironment().setActiveProfiles(....)

Moreover, when I wanted to link directly the two kinds of profile (maven/spring), I was setting the spring.profiles.active property via the maven plugin.

Thoses practices are possibly wrong in the design but they solved my issues.

Horrified answered 26/11, 2014 at 2:19 Comment(0)
M
0

I think it depends on your requirements. If you have different dependencies based on the environment (ie. jdbc drivers, etc..), you'll want to use maven to sort this out.

If it's just a matter of configuring your deployment, you're probably better off using spring.

Moratorium answered 8/8, 2012 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.