Set Maven's pluginGroups at Command Line - maven

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>

Related

Setting the developerConnection for the Maven Release Plugin from the command line

I am currently trying to configure the Maven Release Plugin for our build server.
For that I am trying to set the <scm><developerConnection> through the command line. I read that
project.scm.developerConnection
is the command line property(https://maven.apache.org/guides/mini/guide-releasing.html). I tried to set it but it seems to have no effect. When I start the build, it uses a constructed URL (parent pom url + artifactId) that fails.
I have looked at the source code of the plugin but did not find the command line property mentioned above.
Can anybody shed light on this?
It looks that you cannot pass this property directly from command line. See:
https://issues.apache.org/jira/browse/MRELEASE-707
But you should get it working by specifying it through a custom property in your pom.xml:
<properties>
<my.developer.connection />
</properties>
<scm>
<developerConnection>${my.developer.connection}</developerConnection>
<tag>HEAD</tag>
</scm>
And running maven with, for example:
-Dmy.developer.connection=scm:git:ssh://user#host/repo.git
I use this approach to keep my pom.xml clean when generating a public release that should not contain information about my company's internals.
When you run mvn release:prepare, Maven forks. The arguments supplied on the command line are passed to the initial Maven call (the one you/build server ran) not to the fork.
To pass args to the release plugin, supply the arguments as shown:
mvn release:prepare -Darguments="-Dproject.scm.developerConnection=..." ...
Depending on what I'm trying to do, sometimes I've had to specify in two places, so both original and forked processes get the args:
mvn release:prepare -DsomeArg=val -Darguments="-DsomeArg=val" ...
The first example in the release plugin FAQ shows an example of where the latter is useful.
---- Update ----
I found the property in the maven-scm-plugin code.
Maybe project.scm.developerConnection is read-only? Try setting scmDeveloperConnection instead, as it's listed as the property name.

Force Maven to use System's javac

I have made some code changes to javac and would like maven to use the version of javac that I changed. Unfortunately, it appears that maven ships its own javac implementation. How can I get maven to compile sources using the system wide javac (the one that is executed when running javac in the shell).
Without really knowing what these options mean, I tried providing the fork, and forceJavacCompilerUse which I found here: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
But they do not appear to help at all.
You're in the right ballpark. Look here:
http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html
To avoid hard-coding a filesystem path for the executable, you can use
a property. For example:
<executable>${JAVA_1_4_HOME}/bin/javac</executable>
Each developer then defines this property in settings.xml, or sets an
environment variable, so that the build remains portable.
<settings>
[...]
<profiles>
[...]
<profile>
<id>compiler</id>
<properties>
<JAVA_1_4_HOME>C:\Program Files\Java\j2sdk1.4.2_09</JAVA_1_4_HOME>
</properties>
</profile>
</profiles>
[...]
<activeProfiles>
<activeProfile>compiler</activeProfile>
</activeProfiles>
</settings>
If you build with a different JDK, you may want to customize the jar
file manifest.
I believe the key is setting an explicit <executable>. And I suspect it can probably be hard-coded, without messing with environment variables or other clauses.
See also this link, and look at the "executable" in the sample pom.xml:
Where is the JDK version to be used by Maven compiler specified?
I believe maven looks for JVA_HOME for finding the java. So when you set it to your specific java maven should be able to use it

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

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