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

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.

Related

IntelliJ IDEA says that <systemProperties/> element is not allowed inside <configuration/>

I'm using a plugin in maven that uses Jetty.
In this plugin, I need to made a configuration to set maxFormContentSize:
<plugin>
<groupId>com.organization.example</groupId>
<artifactId>maven-example-plugin</artifactId>
<version>${example.version}</version>
<dependencies>
<!-- -->
</dependencies>
<configuration>
<systemProperties>
<systemProperty>
<name>org.mortbay.jetty.Request.maxFormContentSize</name>
<value>500000</value>
</systemProperty>
</systemProperties>
<script>${example.script}</script>
</configuration>
</plugin>
The problem is that Intellij IDEA says that systemProperties element is not allowed here:
Element systemProperties is not allowed here
What is the correct configuration for the IntelliJ IDEA not show this error? I already made a research about this subject but appears that is the only possible configuration.
I'm using maven 2.2.1 and IntelliJ IDEA 2017.1.4. The Jetty version is 7.6.8.v20121106.
The <configuration> section of a maven plugin can only contain what that specific plugin supports in its various goals.
Not all maven plugins support <systemProperties> only certain ones do.
Since you stubbed out the actual plugin you are struggling with I cannot link you to the specific plugin's documentation page for its goals and configurations.
Look for something like this ...
http://maven.apache.org/plugins/maven-javadoc-plugin/javadoc-mojo.html
... but for your specific plugin
Ask Maven
You can also ask maven, on its command line, to describe the plugin and even a specific goal in the plugin.
Note: the below example command lines work with maven-help-plugin v2.2 or better.
Describe all of the goals:
$ mvn help:describe -DgroupId=org.eclipse.jetty \
-DartifactId=jetty-maven-plugin \
-Dversion=9.4.6.v20170531
Describe a specific goal in detail (with parameters):
$ mvn help:describe -DgroupId=org.eclipse.jetty \
-DartifactId=jetty-maven-plugin \
-Dversion=9.4.6.v20170531 \
-Dgoal=start \
-Ddetail=true

maven update pom property

I'm looking for a way to update pom property to given value, i.e. my pom.xml contains:
<properties>
<abc.def>aaaaa</abc.def>
<properties>
now i want to call :
mvn some_plugin:some_goal -Dabc.def=XYZ
and finally my pom.xml should looks like
<properties>
<abc.def>XYZ</abc.def>
<properties>
I was reading about maven-release-plugin & versions-maven-plugin but i do not see there any matching goal.
Thank you in advance for any reply.
mvn versions:update-properties -Dproperties=[XYZ] -DincludeProperties={abc.def}
Read more here.
and here.
In short:
In versions-maven-plugin, the update-properties goal sets properties to the latest versions of specific artifacts.
includeProperties is a comma separated list of properties to update.
properties are any restrictions that apply to specific properties.
The accepted answer does not work for arbitrary values since it performs sanity checks (links to the documentation for set-property goal since for some reason the documentation for update-properties does not mention this).
To set some arbitrary value on a property use set-property since - as documented - it skips sanity checks:
mvn versions:set-property -Dproperty=your.property -DnewVersion=some_value
Ok, i found some case of solution. I'm using maven-replacer-plugin where:
my properties definition in pom.xml :
<properties>
<abc.def>aaaaa</abc.def>
<properties>
my plugin configuration :
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.2</version>
<configuration>
<file>pom.xml</file>
<replacements>
<replacement>
<token>${abc.def}</token>
<value>${replacer.abc.def}</value>
</replacement>
</replacements>
</configuration>
</plugin>
and finally my maven invocation :
mvn replacer:replace -Dreplacer.abc.def=XYZ
It works for me but I don know is there any better way to achieve it with maven-relase-plugin and/or versions-maven-plugin as #khmarbaise and #Conan said.
I agree with #khmarbaise above, the versions-maven-plugin will do just this, or you could move to the Maven Release Plugin if you want a much heftier approach to managing your versions, but you could also just run a script to sed the pom.xml file using Jenkins' BUILD_NUMBER environment variable, which is a quicker and dirtier approach.

How to ignore a Maven plugin

We have a groupId for Maven plugins:
com.company.maven.plugins
Unfortunately, when I created the first plugin in this groupId, I initially used the wrong naming convention.
maven-myplugin-plugin
The 1.x versions of the plugin used that name. When I realized this was wrong I changed the name to meet the correct convention.
myplugin-maven-plugin
Then I updated the version to 2.x.
In my local settings.xml file I use the pluginGroups to access my plugins from the command line. This particular plugin does not have to be specified in the pom file.
Unfortunately, when I try to access my plugin from the command line without scoping the name I always get the latest version of the incorrect naming convention. So, I get a 1.x version.
Can I tell Maven to ignore the maven-myplugin-plugin artifacts when accessing from the command line (i.e. mvn myplugin:mygoal)?
Some projects still use the old 1.x plugins, so I don't want to delete them from our repository. Also, we are using at least Maven 3.0.3.
It somehow seems that Maven3 resolves the prefixes from plugins in the order of
1. maven-myplugin-plugin
2. myplugin-maven-plugin
3. ... hard-wired groups ...
Following the official naming convention it should be the other way round imho. Nevertheless, I think you do not have a chance to get this fixed. I tried a set of things, basically playing around with the goalPrefix in the maven-plugin-plugin config. Installing a new version of the deprecated-named plugin with goalPrefix did not work. I guess one thing you could do is defining another prefix for your correctly-named plugin, e.g.:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
<goalPrefix>myplugin2</goalPrefix>
</configuration>
</plugin>
Another approach could be to adjust the old plugin's pom.xml, renaming it to something different. But this would imply that your colleagues would need a different execute a different mvn command. Or you can rename your current plugin - similar results.
If there is a better solution, I would also be interested!

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

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

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