Skip tests in Jenkins - maven

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.

Related

Run mvn command on module from existing source

I imported several maven modules on IntelliJ IDEA by using the option File/New/Module From Existing Source. This is working fine but I'm not able to run mvn command lines on one specific module by its module name.
I was able to do it by specifying the path to the pom.xml file by using -f option:
mvn -f "path/to/pom.xml" clean
But I would like to avoid having specifying the path every time I want to run a mvn command. Is their any way to run the command by specifiying the name of the module ?
Thank you.
If you use "Run Anything" then it's possible to select module at the top right corner
You can perform maven install, maven clean etc for a complete module or sub modules of a project using top right option in IntelliJ.
Maven-->select module/submodule folder-->Plugins-->select the option:- deploy, compile, install, clean etc.

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 test scope dependency change does not recompile module's tests

We have a maven multi-module project in which the following weirdness occurred:
module-x has a TEST (src/test/java/...) which depends on code provided by module-y, whose code is not otherwise used in module-x (i.e. nothing in src/main/java/... depends on module-y)
module-x therefore defines a dependency on module-y, but with <scope>test</scope> and uses that code in one of its tests
someone changed a constructor in module-y and committed the code that broke the module-x test (as it was using the old constructor parameters)
TeamCity ran java org.codehaus.plexus.classworlds.launcher.Launcher -f app-parent/pom.xml -B integration-test when it saw the commit
the build succeeded because maven did NOT recompile/rerun module-x TEST code, it just recompiled module-y and everything that depends on it with default compile scope
I'm sure people will point out, why is that test even in module-x, etc, but this weird setup aside for a minute. What I want to understand is this:
If some project (module-x) has a test dependency (module-y) that changes and is recompiled, should not maven then notice this and do a fresh "test-compile" for the project (module-x) that "test-depends" on what changed (module-y)? Is what I saw here normal behavior?
EDIT: from comment replies it seems like the fact that TeamCity is being used may be a factor; I clarified the command used in the sequence list above.
EDIT 2: I should note that the parameter "-f app-parent/pom.xml" is actually the main module that basically depends on "the world" and is where one would run from command-line "mvn test" or "mvn clean package" to rebuild everything.

Why run 'gradle clean build' instead of 'gradle build'?

Why would I run gradle clean build instead of gradle build?
From what I understand, Gradle can detect source changes and update the final artifacts if needed. So why would I still need to clean?
The clean task is defined by the java plugin and it simply removes the buildDir folder, thus cleaning everything including leftovers from previous builds which are no longer relevant. Not doing so may result in an unclean build which may be broken due to build artifacts produced by previous builds.
As an example assume that your build contains several tests that were failed and you decided that these are obsolete thus needs to be removed. Without cleaning the test results (using cleanTest task) or the build entirely (by running the clean task) you'll get stuck with the failed tests results which will cause your build to fail. Similar side effects can happen also with resources/classes removed from the sources but remained in the build folder that was not cleaned.
It removes the build directory. (Build contains the output of the gradle operation)
Other build tools like buck will detect that some tests are removed and won't run them without the needs to run clean target. I think this is pitfall of gradle.
You don't need to run the clean task.
Gradle will track task dependencies and clean appropriate parts for you.
Here's an example Gradle project I created to show that the accepted answer is incorrect.
If custom tasks don't track their dependencies well (they're bugged), then clean is a workaround.

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.

Resources