0

Very new to maven. I have a pom file that I can use to do a build and deploy of my j2ee project and its working fine. (using maven 3).

I was wondering how to set up two different deployment scenario's in the same pom - one to build and deploy in my dev environment and one to build and deploy to a test environment.

The only differences between the two (for now) will be:

dev-build does NOT do an SCM checkout dev-build deploys to tomcat server A

test build does do an SCM checkout test build deploys to tomcat server B

What mechanisms in maven are best to use for creating two different deployment scenarios in this way. I've seen profiles mentioned - is this what I should be using - and if profiles is the answer how do I, for example, include an scm checkout for one profile but not for the other.

Thanks for any replies.

gamozzii
  • 3,911
  • 1
  • 30
  • 34

1 Answers1

3

This definitely sounds like a profile solution would work best. Each profile would have its specific build steps, plugins, properties, etc. The profile can define an activation section to determine when a profile is active. The activation can be base on several things like OS, JDK version, or environment variable. For explicit control, profiles can be toggled on and off using the -P command line option:

mvn -P profile1,!profile2 

That command activates profile1 and deactivates profile2.

Brent Worden
  • 10,624
  • 7
  • 52
  • 57
  • I doesn't think you can create a profile not to checkout from SCM. Are you sure? – Aravind Yarram Feb 01 '12 at 02:58
  • 1
    Assuming checkout is being done using Maven SCM Plugin, configure the plugin in the profile where checkout is needed. For the profile where it is not needed, omit the plugin configuration. – Brent Worden Feb 01 '12 at 04:28
  • The profile approach seems to be right for what I want. I did a bit more reading on them and have got the tomcat deploy working with different profiles. The scm I am doing using the plugin so I think that should work but haven't tried it yet, still getting my head around the scm plugin config, got it part done from command line, need to get it right in the pom. – gamozzii Feb 01 '12 at 10:22
  • As I recall, you can also activate profiles via settings.xml (the one in the Maven install, or the one in the user directory). That could be used to e.g. always do a dev build on developer's machine, and always do a test build on CI server. – Andrew Spencer Feb 01 '12 at 15:51
  • quick update - I got this all working with profiles (the scm goal was done with the scm plugin as suggested above) – gamozzii Feb 06 '12 at 05:13