How can I supply Maven release prepare information without prompts? - maven-2

I want to automate the execution of Maven release:prepare with Perl so that the user doesn't have to answer the prompts for version names etc. Are there a -D arguments that can be supplied so that no prompting is done? I tried the obvious solution which is to feed the prompt answers to mvn via perl code like this:
my $cmd = qq(mvn release:prepare -DautoVersionSubmodules=true-DpreparationGoals="clean install");
open MVN, "| $cmd";
print MVN "\n"; # default
print MVN "$cur_version";
print MVN "\n";
print MVN "$next_version";
print MVN "\n";
close MVN;
but mvn ignores such input and winds up using the defaults (and doesn't prompt either).
So, are there -D args for the release:prepare plugin:goal?
Thanks.

You can use the following maven command to do that...
mvn --batch-mode release:prepare
This will assume defaults for anything that you would normally be prompted for; it would be like running a release and simply hitting enter every time it asked you a question. For instance, if your current development version of your project was 1.2.3-SNAPSHOT, it would release version 1.2.3 and move your development version up to 1.2.4-SNAPSHOT. It is usually best to let Maven work this things out for you anyway since the goal of maven is to use convention over configuration. However, is you need to specify non-default properties, the maven-release-plugin allow command line property override as well as using a 'release.properties' file for overriding these settings.

For the Maven part, see Performing a Non-interactive Release.

If it is a Perl solution you seek, command-line arguments are usually executed through the system command.
Try system $cmd;
As far as I can tell, there's no need to open and close filehandles.

You can specify everything using arguments to the mvn release:prepare command:
mvn release:prepare -DautoVersionSubmodules=true -DreleaseVersion={your release version} -DdevelopmentVersion={next version}-SNAPSHOT -Dtag={your tag}

Related

How do we generate seedstack project for a specific release?

We want to generate a new project to test few things on specific release for e.g; 16.11.2 (Kiwi release)
What -additional params that is required to pass with the given command
mvn -U org.seedstack:seedstack-maven-plugin:generate
Regards
Indrajit
You can generate a project for a specific version by manually specifying the archetype version (which always matches the SeedStack version).
For SeedStack 16.11.2:
mvn -U org.seedstack:seedstack-maven-plugin:generate -DarchetypeVersion=16.11.2
See the related documentation for additional parameters and information.

Find classpath maven is using for running testng testcase

what options to maven can I use to determine what classpath maven is running a testng test case with?
You didn't provide the Maven version, but at least in 3.x (and maybe also 2.x) you can run commands with the -X (debug) option. That way the Test Classpath is printed out before tests are run.
mvn test -X
In general you can find the classpath that maven is using by using the built-in maven dependency plugin and its build-classpath goal.
If you want the classpath uses for compiling and running the test you need to select the test dependency scope. This scope is the default, but if you want to be explicit you can set it with -DincludeScope=test.
Other scopes include runtime, compile, provided and system.
Depending on how you want to consume the output you can play with the options -Dmdep.outputFilterFile and -Dmdep.outputFile. The mdep.outputFilterFile makes it easier to parse the output from a script and the outputFile option writes to a file instead which some tools can read directly.
Here are some examples:
$ mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFilterFile=true|grep 'classpath='
classpath=xxx.jar:yyy.jar
$ mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=cp.txt
$ cat cp.txt
xxx.jar:yyy.jar
I couldn't format my response in my comment so submitting the grepped version here:
mvn test -X | grep "maven.dependency.classpath"

maven log file configuration

How can I configure logging for maven build? The log which maven generates is not providing enought information like time stamp with each log statement. Where/what log config file maven uses?
You may be aware of this, and it will not print dates, but use mvn -X to print verbose output.
Additionally, you can always pipe the output of maven to some other utility (assuming your shell environment contains halfway competent tools). For instance mvn -X clean | awk '{print "("d")"$0}' "d=$(date)" prints out a date before each line in maven. I didn't bother formatting the date, but that's easily done with arguments to the date executable. Note that this won't really work for maven commands that require interactive user input, such as maven archetype:generate.
Answer provided by #whaley is a good direction. However, the $(date) is evaluated only once at the beginning and then remains the same.
I had to use an approach mentioned in Is there a Unix utility to prepend timestamps to stdin?:
mvn -X <goals> | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; }'
As suggested by #eckes, default logging configuration file is available at /conf/logging/simplelogger.properties, from Maven 3.1.0 onward.
Change "org.slf4j.simpleLogger.showDateTime" property value to "true"
org.slf4j.simpleLogger.showDateTime=true
To change dateTimeFormat, as default is relative time in milliseconds.
Add below line in simplelogger.properties file.
org.slf4j.simpleLogger.dateTimeFormat=HH:mm:ss:SSS
References:
Maven logging: https://maven.apache.org/maven-logging.html
DateFormats: http://docs.oracle.com/javase/1.5.0/docs/api/java/text/SimpleDateFormat.html
This still seems some closed issue in Maven, as you can see on:
https://issues.apache.org/jira/browse/MNG-519
The provided workaround looks not too bad, but you need to modify the maven installation.
Maven in Version 3.1 and 3.2 allow simpler configuration of the SLF4J based logger. You can specify "-l logfile" on the command line, and the default configuration of the SimpleLogger is in the config file conf/logging/simplelogger.properties.
If you want to turn on the default timestampts (milliseconds since start) you can simple change the property in this file: org.slf4j.simpleLogger.showDateTime=true.

Passing the Maven Debug Flag from Hudson

I'm having an issue with a maven build in hudson. This issue would be fairly easy to resolve if I could see the output of maven with the -X flag passed in. However I can't find a way to do this. If I specify "-X" in the "Goals and options" field of the "Build" section in the job configuration my console output looks exactly the same as if I had not passed the "-X" flag at all. Is the debug logging going somewhere else? Or is there some other way I need to pass the "-X" flag?
UPDATE:
The reason this isn't working is because the build is failing during the "Parsing POMs" part of the hudson process, before it actually kicks off the true maven build and passes in any params I specify in the project. So what I really need is a way to get better logging during the "Parsing POMs" part of a maven build in hudson.
That's what it says in the help text.
Specifies the goals to execute, such
as "clean install" or "deploy". This
field can also accept any other
command line options to Maven, such as
"-e" or "-Dmaven.test.skip=true".
I would have put it there as well.
The maven help gives me the following two options:
-X,--debug Produce execution debug output
-e,--errors Produce execution error messages
May be you can try the --debug or the -e swtich
In Jenkins, and I assume this is true for Hudson as well, command line arguments can be passed to Maven in the "goals" setting. I was able to pass the -X parameter by adding it to the beginning of the "goals".
-X package install
Jenkins apparently blindly appends this setting to the end of the mvn command-line.
I have exactly the same problem with Hudson 1.398 (Maven 2.0.10, jdk 1.6.0_07): the build fails during the parsing of the pom files. It works locally and when launched manually from the Hudson workspace.
That build needs an environment variable to be set (for the path of a module), but the environment variable doesn't seem to be propagated from Hudson to Maven. So, like you, I have also tried to get more details from Maven with the -X option, but it also doesn't seem to be propagated.

Passing extra parameters to release:prepare, but not to release:perform

When preparing the release of a Maven 2 project which includes a GWT module, mvn -B release:prepare release:perform builds the GWT module twice, which takes up most of the time of the build.
Running a full GWT build is not necessary when executing release:prepare, a validate-only build is enough. This would be achieved by specifying the -Dgwt.validateOnly=true flag on the command line, but the command line arguments are passed to a single execution when using the Maven 2 Release plugin plugin under Hudson.
How can I pass the -Dgwt.validateOnly flag to release:prepare but not to release:perform?
Do it yourself and create two steps.
mvn -B release:prepare -Dgwt.validateOnly=true
mvn -B release:perform
EDIT: Just read the documentation of the M2 Release Plugin. I suggest to use the standard Release Plugin or the Batch Task Plugin .