2

Is there any way I can use two different profiles in settings.xml file to execute two different builds on different servers? For eg: In my settings.xml file I have two profiles:

<profile>
      <id>test1</id>
      <properties>
          <liferay.version>6.2.10.9</liferay.version>
          <liferay.maven.plugin.version>6.2.10.6</liferay.maven.plugin.version>
          <liferay.auto.deploy.dir>Server1 Details</liferay.auto.deploy.dir>
          <liferay.app.server.deploy.dir>Server1 Details</liferay.app.server.deploy.dir>
          <liferay.app.server.lib.global.dir>Server1 Details</liferay.app.server.lib.global.dir>
          <liferay.app.server.portal.dir>Server1 Details</liferay.app.server.portal.dir>
      </properties>
</profile>      
<profile>
      <id>test2</id>
      <properties>
          <liferay.version>6.2.10.9</liferay.version>
          <liferay.maven.plugin.version>6.2.10.6</liferay.maven.plugin.version>
          <liferay.auto.deploy.dir>Server2 Details</liferay.auto.deploy.dir>
          <liferay.app.server.deploy.dir>Server2 Details</liferay.app.server.deploy.dir>
          <liferay.app.server.lib.global.dir>Server2 Details</liferay.app.server.lib.global.dir>
          <liferay.app.server.portal.dir>Server2 Details</liferay.app.server.portal.dir>
      </properties>
      </properties>
</profile>  
<activeProfiles>
      <activeProfile>test1</activeProfile>
      <activeProfile>test2</activeProfile>
</activeProfiles>

Now, I want "test1" profile for one project and "test2" for another project and I want my pom.xml build properties to be fetched from settings.xml profile's properties.

If I keep both profile in "activeProfiles", my both projects pick "test2" details and build & deploy to wrong server.

In pom.xml I'm using build>plugins>configurations like this:

      <configuration>
                <autoDeployDir>${liferay.auto.deploy.dir}</autoDeployDir>
                <appServerDeployDir>${liferay.app.server.deploy.dir}</appServerDeployDir>
                <appServerLibGlobalDir>${liferay.app.server.lib.global.dir}  </appServerLibGlobalDir>
                <appServerPortalDir>${liferay.app.server.portal.dir}</appServerPortalDir>
                <liferayVersion>${liferay.version}</liferayVersion>
                <pluginName>portlet-name</pluginName>
                <pluginType>portlet</pluginType>
      </configuration>

Please help!

Thanks in advance!

PanwarS87
  • 319
  • 5
  • 14
  • See here: http://stackoverflow.com/questions/5676231/how-to-activate-profile-by-means-of-maven-property – Multisync Oct 16 '14 at 22:08
  • Re _"I want 'test1' profile for one project and 'test2' for another project"_. Do you have one or two Maven projects, i.e. POMs? – Gerold Broser Oct 18 '14 at 02:59
  • yes, two diff pom.xml with configurations properties. – PanwarS87 Oct 18 '14 at 03:10
  • If you have two POMs why do you fiddle around with profiles? Write the appropriate properties into each POM thus getting rid of the profiles completely. In the best sense of the [KISS principle](http://en.wikipedia.org/wiki/KISS_principle). Remember also what the 'M' on POM stands for. If your model needs a certain server to work with it's a requiremennt for this model and belongs there. – Gerold Broser Oct 18 '14 at 12:43

2 Answers2

1

I resolved this problem by creating two different profile in my settings.xml and kept empty. As, I was using eclipse I selected diff profiles for Projects from eclipse Maven > Select Profile. That way I have the choice of selecting any profile for my project and deploy to selected profile server.

Reason I did this way: In a collaborative team env, we only need to share the settings.xml file and select profile before deploying. No need to change the pom.xml every-time.

If somebody has a better solution, please post. It is always good to learn new stuff.

PanwarS87
  • 319
  • 5
  • 14
0

It's no wonder that test2 is picked. With both test1 and test2 in <activeProfiles> both are always active regardless of (repeated, hence pointless) POM or cmd line activation.

You most probably configured the same settings in either of the two and although POMs and settings.xmls are declarative, i.e. there's no program flow within them, there is a flow when parsing them at Maven runtime. Then test2 is the latter and overwrites the settings of the previous test1.

According to Introduction to Build Profiles, Deactivating a profile: "Starting with Maven 2.0.10, one or more profiles can be deactivated using the command line by prefixing their identifier with either the character '!' or '-' ".

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107
  • Hi Geri, I'm using build>plugins>configuration in pom.xml which are mentioned in settings.xml. So, now to maintain two different profiles where should I specify server details. – PanwarS87 Oct 18 '14 at 02:17
  • @PanwarS87 Did you follow the link to the guide? 1. Deactivate one or the other on the cmd line: `mvn -P !test[1|2]`. 2. Remove `` completely and activate one or the other on the cmd line: `mvn -P test[1|2]`. – Gerold Broser Oct 18 '14 at 02:55
  • Sorry to ask this again but do I need to maintain profile in pom.xml? How can I run "clean install -P !test2" from eclipse? – PanwarS87 Oct 18 '14 at 03:23
  • @PanwarS87 This would be off-topic for this thread. Ask a new question and tag it with _Eclipse_ and _Run Configuration_. – Gerold Broser Oct 18 '14 at 03:28