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

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.

Related

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

Maven: how to know where is local repository (localRepository/M2_REPO) in an efficient way?

For a build integration between maven based projects and the rest of world, I need to be able to find out where Maven thinks the local repository for the current user/build is, but from outside Maven.
For now, I use:
mvn help:evaluate -Dexpression="localRepository" | grep basedir | sed -e "s/.*>\(.*\)<.*/\1/")
This works (or seems to work in the subsets of cases I met), but it is extremelly slow: each call to that line takes a couple of seconds (starting the JVM, letting maven do what it needs, etc). It is unberable in an interactive build.
So, does anybody know if there is a quicker way to find that?
I believe I can't just look for the M2_REPO environment variable, as the value can be defined elsewhere (in user settings.xml? And elsewhere?)
My better idea for now is to set an envirnment-variable with the key builtd based on the project path to at least limit the evaluation slow-down to one time.
Any ideas or insigh would be very helpfull.
The local repository can be found in .m2/repository in the user directory unless it is specified otherwise in the settings.xml.
Parse the settings.xml.

Pass/share parameter values between dependant builds in TeamCity

Setup: Build CD has has Artifact Dependency and Snapshot Dependency on Build CI. Build CI pulls from VCS root and generates artifacts for Build CD.
Problem: In Build CD I need %teamcity.build.branch% parameter, but it's not available, because it only uses artifacts and has no VCS Roots linked.
Question: Is there a way to pass parameters between dependant builds? (search results in the googles seem of topic)
Workaround 1: I can access %teamcity.build.branch% in Build CD if I link it to same VCS root Build CI is using, but I'd like to avoid having this link and Build CD unnecessarily pulling from VCS (build log shows it does this).
Workaround 2: I could write parameter to a file in Build CI and read from it in Build CD later. This is a hack and I would like to avoid it as well.
Absolutely. In CD, add a parameter called whatever, with value equal to %dep.Build_CI.teamcity.build.branch%. TeamCity will help you figure out the exact value thanks to its auto-suggestion/auto-completion, once you type %dep..

Where does Jenkins store the project source

I have a Jenkins job that uses a script to build my project. On the following line, the script fails mvn -e -X -Dgit='$git' release:prepare.
Because I want to search for the cause of this, I want to go to the Jenkins server and run mvn -e -X -Dgit='$git' release:prepare from the command line, to see if it works.
Does Jenkins store the projects' source code somewhere, such that I can go to that folder and call Maven?
If yes, then where?
Yes, It Stores the project files for the job by default at
/var/lib/jenkins/workspace/{your-job-name}
This is where jenkins suppose the project files to be present or it pulls it from a source before start working/building from it.
Quote from Andrew M.:
"Hudson/Jenkins doesn't quite work that way. It stores configurations and job information in /var/lib/jenkins by default (if you're using the .deb package). If you want to setup persistence for a specific application, that's something you'll want to handle yourself - Hudson is a continuous integration server, not a test framework.
Check out the Wiki article on Continuous Integration for an overview of what to expect."
From this Question on serverfault.
This worked for me:
/var/jenkins/workspace/JobNameExample
but, if your build machine (node) is a different than the one where Jenkins is running (manager), You need specify it:
/var/jenkins/workspace/JobNameExample/label/NodeName
Where you can define label too:
jenkins stores its workspace files currently in /var/jenkins_home/workspace/project_name
I am running from docker though!

Skip tests in Jenkins

I've set up a build on Jenkins for a Maven project, and I would like to build it without running any of the tests. I've tried entering "clean install -DskipTests" in the goals field, like this:
But it doesn't work. What am I doing incorrectly?
Note: I want to skip the tests without touching the pom. I have a separate build that DOES run the tests.
The problem is that I omitted =true. I was able to build without running tests by entering:
clean install -DskipTests=true
Just to extend the answer, maven has 2 options for skipping tests:
-DskipTests=true — The one that was mentioned. With this parameter, maven ignores tests completely.
-Dmaven.test.skip=true — With this option maven compiles the tests but doesn't launch them.
So you may want to use the second option instead as fast code compile validation. E.G.: if you develop some library or module that will be used by some one else you must be sure that you don't brake contract with the client. Tests compilation can help you with this.
Use either of these parameters depending on your needs.
use "Goals and options" value is "clean install -DskipTests=true".
it works like a Charm. I saved hours of time using this Option. :-)
I use option "-DskipTests=true" in "Invoke top-level Maven target" -> "JVM Options" and it works fine.

Resources