2

Is there a way to activate a Maven profile only if a project is (or is not) being deployed?

nexus staging plugin deploys all modules that are part of a reactor build so I want to skip certain modules (unit tests, benchmarks, etc) if the project is being deployed (to deploying them).

I know I can invoke mvn -Ddeploy deploy and activate profiles based on the deploy property but I'm hoping there is a way to avoid mentioning deploy twice.

Gili
  • 86,244
  • 97
  • 390
  • 689

1 Answers1

0

AFAIK, you cannot do that.

There is list of possible profile activations (https://maven.apache.org/guides/introduction/introduction-to-profiles.html), stating:

A profile can be triggered/activated in several ways:

  • Explicitly
  • Through Maven settings
  • Based on environment variables
  • OS settings
  • Present or missing files

My guess is that profiles are evaluated before the phases/goals are even read by Maven. I tried to figure it out from https://stackoverflow.com/a/14727072/927493, but it does not say it explicitly.

It may help, though, to set <skip>true</skip> for the deploy plugin in the respective modules (the property maven.deploy.skip could also be used).

https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html

Community
  • 1
  • 1
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142