How to speed up maven-help-plugin:evaluate? - maven

I'm using maven-help-plugin one-liner to grab the project version in a bash script:
currentVersion=`mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout`
It runs in a few seconds locally but takes over 2 minutes when it runs on our build agents. I ran it with -X and I didn't see anything obviously alarming though it did run a bit more quickly. I also tried running it with -o in case it's dependency downloading or some network hiccup slowing it down but it just fails to find the plugin and doesn't run at all.
Is this just a known slow command, or could the command run faster if I configured it differently or adjusted my POMs in some way?
But with it taking 2+ minutes I may need to drop the maven way in favor of xmlstarlet or something to treat the POM as just XML.

Related

Maven build through Jenkins pipeline takes 4 times longer than usual

Our Jenkins pipeline has a stage to build with following command -
mvn clean install -DdestFolder=<destination-folder-path>
Above command takes 1 hour when run through pipeline. If same is run locally from same machine, it takes only 15 mins.
When run through Jenkins pipeline, I can see enough memory, enough space. Also I had explicitly assigned memory to maven using MAVEN_OPTS, still same result.
Could you please help to understand what could be wrong here?

Make maven output show progressed sub-modules only

I am working with an automatic build script in maven 3.x. The parent project contains of more than 60 modules. The compilation is done in a shell script simplified this way:
for each module:
cd module
mvn clean install > compile.$module.log
echo "Compiled $module"
I like to see a list of compiled modules in order to see the progress or the build. I like to have a big maven command and avoid the manual for loop. I hope to speed up the build this way, since splitting the parent project into more independent modules is not a short time option, yet.
The --quiet flag might be enough already. Alternatively a user defined logging implementation would be fine as well, as described in the manual (https://maven.apache.org/maven-logging.html)
The questions are:
What is the prefered way to modify maven log output?
Does anyone already know a ready-to-use plugin for my purpose?
Thanks

How to use incremental mode in SonarQube?

I've trying to fiddle with SonarQube and now I'm learning about the incremental mode. In my understanding it should analyze only the changed files.
So my first test is just to run SonarQube twice on our project without any change. I run SonarQube (5.1.2) installed locally on windows 7 64-bit machine with SSD drive and I7 CPU. We use java 1.7 and Maven 3.3.3. Our project is fairly big (~570 modules) of maven, most of them are java code. After I run a prepare-agent of jacoco along with my unit tests I understand that its time to run sonar:sonar and create a report.
So what I try is:
mvn sonar:sonar -Dsonar.analysis.mode=incremental -Dsonar.host.url=http://localhost:9000 -Dsonar.java.coveragePlugin=jacoco
This runs for 20 minutes. Ok, now I run the same command again without doing any change and it still runs the same 20 minutes
So my question is - whether someone can explain me how to use the incremental mode correctly? I have a hard time understanding what I'm doing wrong, in my understanding the second run has to be much faster, otherwise I don't see any advantage over the preview mode here.
Thanks Mark
The incremental mode will analyze only changed files since latest "regular" analysis on server. So in your case you should first run a normal (now called "publish") analysis:
mvn sonar:sonar -Dsonar.java.coveragePlugin=jacoco
Then your can use the incremental mode:
mvn sonar:sonar -Dsonar.analysis.mode=incremental -Dsonar.java.coveragePlugin=jacoco

Which Maven goal to use as no-op (for scripting purposes)?

I have a script on Jenkins CI which optionally does dependency:go-offline. The other option should be to do nothing. But I can't put "" in there - it must be a goal.
So - which one would you pick? It should:
Be in central, always reachable
Take minimum time
Have minimal output
Have no side effects
I was thinking of some help:... goal but those tend to have a lot of output. Any better?
You can use this goal and option:
mvn --quiet help:help
the -q,--quiet option causes the output to only show errors.
Note that Jenkins allows you to add options like --quiet as diplayed in the usage: mvn [options] [<goal(s)>]. You configure these in the Jenkins job’s “Goals and options” field.
Check mvn --help output for further information.
I know this is an old question, but I came across it when I had the same requirement and it's still unanswered, so I'm posting for anyone who needs it in future.
This still depends on the current project, but could be useful if you don't want to hardcode a specific plugin for some reason:
mvn -pl ./ validate
-pl ./ means only current project, ignore submodules. Alternatively you could specify specific project by relative path or [groupId]:artifactId.
validate is the first phase of the Default Lifecycle. Doesn't change or build anything.
Alternatively, if you don't have a maven project at all, some maven plugins, or rather specific plugin goals, can be executed without it. E.g.:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:help
It would still scan projects if it sees a POM in the current directory. And of course you still need to have the plugin in your local repository.

Can Maven be made less verbose?

Maven spews out far too many lines of output to my taste (I like the Unix way: no news is good news).
I want to get rid of all [INFO] lines, but I couldn't find any mention of an argument or config settings that controls the verbosity of Maven.
Is there no LOG4J-like way to set the log level?
You can try the -q switch.
-q,--quiet Quiet output - only show errors
-q as said above is what you need. An alternative could be:
-B,--batch-mode
Run in non-interactive (batch) mode
Batch mode is essential if you need to run Maven in a non-interactive, continuous integration environment. When running in non-interactive mode, Maven will never stop to accept input from the user. Instead, it will use sensible default values when it requires input.
And will also reduce the output messages more or less to the essentials.
My problem is that -q is too quiet. I'm running maven under CI
With Maven 3.6.1 (April 2019), you now have an option to suppress the transfer progress when downloading/uploading in interactive mode.
mvn --no-transfer-progress ....
or in short:
mvn -ntp ... ....
That is what Ray proposed in the comments with MNG-6605 and PR 239.
Official link :
https://maven.apache.org/maven-logging.html
You can add in the JVM parameters :
-Dorg.slf4j.simpleLogger.defaultLogLevel=WARN
Beware of UPPERCASE.
Use the -q or --quiet command-line options
If you only want to get rid of the [INFO] messages you also could do:
mvn ... | fgrep -v "[INFO]"
To suppress all outputs (except errors) you could redirect stdout to /dev/null with:
mvn ... 1>/dev/null
(This only works if you use bash (or similar shells) to run the Maven commands.)
The existing answer help you filter based on the log-level using --quiet. I found that many INFO messages are useful for debugging, however the downloading artifact log messages such as the following were noisy and not helpful.
Downloading: http://nexus:8081/nexus/content/groups/public/org/apache/maven/plugins/maven-compiler-plugin/maven-metadata.xml
I found this solution:
https://blogs.itemis.com/en/in-a-nutshell-removing-artifact-messages-from-maven-log-output
mvn clean install -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn
Maven 3.1.x uses SLF4j for logging, you can find instructions how to configure it at https://maven.apache.org/maven-logging.html
In short: Either modify ${MAVEN_HOME}/conf/logging/simplelogger.properties, or set the same properties via the MAVEN_OPTS environment variable.
For example: setting MAVEN_OPTS to -Dorg.slf4j.simpleLogger.log.org.apache.maven.cl‌​i.transfer.Slf4jMave‌​nTransferListener=wa‌​rn configures the logging of the batch mode transfer listener, and -Dorg.slf4j.simpleLogger.defaultLogLevel=warn sets the default log level.

Resources