Maven: How to pass command-line arguments from release:perform to deploy? - maven

When I invoke release:peform on my project. it invokes deploy which in-turn invokes gpg. I'd like to pass the gpg passphrase into the process using a system property or environment variable but neither seems to work.
If I invoke mvn.bat '-Darguments="-Dgpg_passphrase=test"' -Pwindows-i386-msvc-debug -DconnectionUrl=scm:hg:https://boost-maven-project.googlecode.com/hg/ release:perform Maven ends up invoking:
cmd.exe /X /C mvn deploy --no-plugin-updates -Psonatype-oss-release -P windows-i386-msvc-debug,always-active -f pom.xml"
And as you can see, neither environment variables nor the -Darguments command-line arguments are passed to the deploy goal. Any ideas?

You have configured as -Denv.gpg_passphrase=test, Please correct me, if I'm wrong. I understand that you are trying to pass the environment variable which is not allowed here. it is a system properties named env.gpg_passphrase instead. The -D is always the system properties.
If you would like to use the environment variable, please configure through the OS configuration instead. If you would like to use the system properties please use -D. Please do not mix these two types.
IMHO, I've a scenario as your mentioning to sign the artifact as well. I configure by specifying the "maven-release-plugin" explicitly at the build section as the following example.
<build>
<plugins>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>${my.maven.release.version}</version>
<configuration>
<arguments>${my.release.arguments}</arguments>
</configuration>
</plugin>
<plugins>
</build>
I also configure the properties named my.release.arguments at each developer settings.xml for security purpose (do not share the secret, e.g. user/password/private key,etc.). I am able like to know and identify who releases these artifacts by looking at the signature.
I hope this may help.
Regards,
Charlee Ch.

It turns out this is caused by a Sonatype bug: https://issues.sonatype.org/browse/CENTRALSRV-35

Related

Setting application-specific properties on deploy by maven

I would like to deploy java app twice to one tomcat server, each time with different environment properties.
I would like to find a way like
mvn tomcat7:deploy -Denvironment=local
I don't mind using other maven plugin.
With no need to change files after deploy.
Is it somehow possible?
Thank you for you answer.
You can have a configuration file (something like e.g. application.properties) that you enable resource filtering for. You could then parameterize the values in that configuration file, and pass in different parameter values for each of the deployments (-Dkey1=value1 -Dkey2=value2).
You could pass the different parameter values on the command-line, or you could cement them in different profiles, and just activate the appropriate profile from the command-line (-Psecond-deployment).
What seems a little unfortunate from the suggested approach in your question is: in its most basic sense Maven is a build tool, meant to produce a consistent artifact from a build. This is no longer the case with the suggested approach in your question. If this is a web application that is never used as a dependency of other module, this may be fine. But just highlighting that different deployment configurations is a deployment concern, not a build concern.
I used little workaround.
I created different profiles which I use to update application property.
example:
In my POM I have:
<profiles>
<profile>
<id>local</id>
<properties>
<environment>local</environment>
....
</properties>
</profile>
and in application.property file I have
environment=#environment#
(That # are correct! )
This way I can deploy my app with defined environment by using command
mvn -P local tomcat7:deploy
and use environment variable anywhere else as ${environment}

How can I specify complex Maven configuration options on the command line?

For example, I want to use the Wildfly deploy plugin, as outlined here:
http://docs.jboss.org/wildfly/plugins/maven/latest/deploy-artifact-mojo.html
To deploy, I would use a command like mvn wildfly:deploy -Dfilename=my.ear. But let's say I want to deploy to a particular server group. Using a POM, I would add:
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.1.0.Alpha1</version>
<configuration>
<domain>
<server-groups>
<server-group>main-server-group</server-group>
</server-groups>
</domain>
</configuration>
</plugin>
But if I can't change the POM, how would I pass this configuration in on the CLI or in $HOME\.m2\settings.xml?
The usage page indicates a configuration "type" of org.wildfly.plugin.deployment.domain.Domain for a "domain" option but I don't know how to type those options out on the CLI. Obvious answers like -Ddomain.server-groups.server-group=my-server-group don't seem to work.
If you could change the pom using a property like <server-group>${server.group}</server-group> should work. I don't think maven has support for complex attribute properties like that.
If that's not possible you could file a feature request.
Not exactly the answer to the overall question, but to your specific problem.
Changing the version in the pom to 1.2.2.Final, you can now do:
-Dwildfly.serverGroups=main-server-group
which I guess wasn’t available in 1.1.0.

Maven: Only execute plugin when a command line flag is present

I want Maven to only run a certain plugin when there is a flag on the command line when I call the mvn command.
for example:
Let's say I have a plugin called maven-foo-plugin. I only want maven to run this plugin when the flag --foo is present when I call the maven command.
So, instead of saying...
mvn install
...I would say...
mvn install --foo
The first one should NOT use/call the plugin maven-foo-plugin, but the second one should. By default, I don't want this plugin to run, but if and only if, the --foo is present. Is there another parameter that I add to this maven-foo-plugin to make it do this?
The plugin I'm using is the maven-antrun-plugin that has the task that unzips a file. Of course, sometimes this file is present and sometimes not. Sometimes, it's not present and I don't need it. So, I need a way (Preferably through command line unless someone has a better idea) to turn on/off this plugin.
As #Gab has mentioned, using Maven profiles is the way to go. Create a profile and configure your plugin in the profile. Then in the profile's activation section, reference the environment variable, with or without a value:
<profiles>
<profile>
<activation>
<property>
<name>debug</name>
</property>
</activation>
...
</profile>
</profiles>
The above example would activate the profile if you define the debug variable when calling Maven:
mvn install -Ddebug
Please note that you have to prefix environment variables with -D in order to pass them to the JVM running Maven.
More details can be found here: http://maven.apache.org/guides/introduction/introduction-to-profiles.html
The correct way to trigger conditional action in maven is to use profile.
You can so configure a specific profile including the plugin activation, you will then trigger the execution using
mvn targetPhase -P myprofile
(you can also specify a specific property value to activate the profile)
see Maven: Using a Plugin Based On Profile

Set Maven's pluginGroups at Command Line

Is it possible to set Maven's pluginGroups property via the command line?
I know it's possible to set in the settings.xml file as documented here, but I'd really like to pass it as a parameter on certain jobs.
To be clear what I mean, this is what I'd have to stick in settings.xml:
<pluginGroups>
<pluginGroup>com.mycompany.maven.plugins</pluginGroup>
</pluginGroups>
This is configuration parameter - so it is hard to define. Try to create file with alternative setting and call maven:
mvn -s alternativaSettings.xml <goals>

Specifying Maven memory parameter without setting MAVEN_OPTS environment variable

I was wondering if it is possible to specify Maven memory boundaries with a syntax similar to:
mvn -Dtest=FooTest -DXmx=512M clean test
I tried a couple of variations till now, unsuccessfully.
I am aware of MAVEN_OPTS environment variable, but I would like to avoid that.
Related to the above question, it would be nice to know if there is the possibility to specify the memory behavior of the surefire plugin in a similar manner, so that it forks the jvm using the overridden memory amount (eventually overriding the <argLine> parameter in the pom plugin configuration, if present)
To specify the max memory (not via MAVEN_OPTS as originally requested) you can do the following:
mvn clean install -DargLine="-Xmx1524m"
You can configure the surefire-plugin to use more memory. Take a look on
Strange Maven out of memory error.
Update:
If you would like to set the parameter from command-line take a look on {{mvn.bat}} (or {{mvn}} shell script) in your maven installation directory. It uses with additional options specified in command line.
Next possibility is to set surefire-plugin and use properties specified in command-line, e.g. mvn ... -Dram=512
and
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.5</version>
<configuration>
<forkMode>once</forkMode>
<argLine>-Xms${ram}m -Xmx${ram}m</argLine>
</configuration>
</plugin>
Since Maven 3.3.1 a default can also be specified in ${maven.projectBasedir}/.mvn/jvm.config
It is documented here: https://maven.apache.org/docs/3.3.1/release-notes.html#JVM_and_Command_Line_Options

Resources