mvn package failes even with -DfailIfNoTests=false - maven

I have a maven build which I would like to execute the jar creation for, but mvn package fails due to unit test failures.
I'd like to still build the jar in spite of the fact that some tests fail, I tried
mvn package -Dtest=false -DfailIFNoTests=false
But that fails.
mvn jar:jar seems to work, but I'd rather use the more idiomatic mvn package approach.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.119s
[INFO] Finished at: Mon Mar 11 12:07:16 EDT 2013
[INFO] Final Memory: 9M/234M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project glusterfs: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]

The surefire plugin controls test running and failure reporting.
mvn package -Dmaven.test.failure.ignore=true
should compile and run your tests, but not fail the whole build if some of the tests fail. (I've never used this, going on reading docs only.)

You can skip running unit tests with the following:
-Dmaven.test.skip=true

Related

Fresh Vaadin 8.1 app "multimodule" app fails to build

When creating a new Vaadin 8.1.0 app named bogus using the archetype vaadin-archetype-application-multimodule, the build fails in IntelliJ 2017.2 when running Maven Projects panel > bogus-ui > Plugins > jetty > jetty:run
I get these error messages on console.
/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java -Dmaven.multiModuleProjectDirectory=/Users/basilbourque/IdeaProjects/bogus/bogus-ui "-Dmaven.home=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3" "-Dclassworlds.conf=/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/bin/m2.conf" "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=55637:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA.app/Contents/plugins/maven/lib/maven3/boot/plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version=2017.2 org.eclipse.jetty:jetty-maven-plugin:9.3.9.v20160517:run
objc[11304]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/java (0x1060bd4c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x10712c4e0). One of the two will be used. Which one is undefined.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building bogus-ui 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> jetty-maven-plugin:9.3.9.v20160517:run (default-cli) > test-compile # bogus-ui >>>
Downloading: http://maven.vaadin.com/vaadin-addons/com/example/bogus-backend/1.0-SNAPSHOT/maven-metadata.xml
Downloading: http://maven.vaadin.com/vaadin-addons/com/example/bogus-backend/1.0-SNAPSHOT/bogus-backend-1.0-SNAPSHOT.pom
[WARNING] The POM for com.example:bogus-backend:jar:1.0-SNAPSHOT is missing, no dependency information available
Downloading: http://maven.vaadin.com/vaadin-addons/com/example/bogus-backend/1.0-SNAPSHOT/bogus-backend-1.0-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.334 s
[INFO] Finished at: 2017-07-30T22:58:18-07:00
[INFO] Final Memory: 11M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project bogus-ui: Could not resolve dependencies for project com.example:bogus-ui:war:1.0-SNAPSHOT: Could not find artifact com.example:bogus-backend:jar:1.0-SNAPSHOT in vaadin-addons (http://maven.vaadin.com/vaadin-addons) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
Process finished with exit code 1
Using Java 8 Update 144 on macOS Sierra 10.12.5 with IntelliJ Ultimate edition 2017.2.
The linked Question, Maven: How to use jetty:run in a multi-module Maven project, without needing to install, is not a duplicate of this Question. That one asks about one module (the Web Module) picking up on changes made in other modules and causing a rebuild rather than retrieving built items from local repository. I am asking how to run the app in the first place, long before needing to trigger re-builds.
Lifecycle > install on root/parent module
Maven needs to find dependencies before running.
You need to run 'mvn install' on root (parent) project or on your backend module (and other project that backend depends on).
you need to run mvn clean install command on the the parent project from root directory>

Life cycle error in jenkins

After building my project in Jenkins, I ran into this error:
<===[JENKINS REMOTING CAPACITY]===>channel started
log4j:WARN No appenders could be found for logger
(org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
Executing Maven: -B -f /var/lib/jenkins/jobs/A/workspace/pom.xml mvn clean
integration-test -Dlog4j.configuration=file./src/test/
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Invalid task 'mvn': you must specify a valid lifecycle phase, or a goal in the
format plugin:goal or pluginGroupId:pluginArtifactId:pluginVersion:goal
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
This is a little weird, since I was to build the project using maven via the command line. Why is my repository, via Jenkins not able to build the project, while I could on my local machine?
The answer is right in your log file
Executing Maven: -B -f /var/lib/jenkins/jobs/A/workspace/pom.xml mvn clean.
You have miss-configured the job, so it's now trying to execute an in-existent mvn task. If your project type is "maven", just type clean compile package etc in the input box. Otherwise please post a screenshot of your job's config so we can better understand what's going on
It looks like you are specifying mvn as a goal to maven. The Goals and options line in jenkins project config should not include mvn: clean integration-test for example.
I personally solved such an error doing a mere
rm -rf /var/lib/jenkins/jobs/A/workspace
which does equivalently reset everything clean when such a 'sandgrain' has gotten inside somehow and corrupted the build.

Build failure on terminal for junit test case

I am new to maven and junit so please bear with me :-)
I have created a sample maven project which contains one simple test in src/test/java as folows
public class AssertUnitTest {
#Test
public void massageTest(){
Assert.assertEquals("abc", "abd");
}
}
when i run the test from eclipse, test fails saying that the expected is abc but found abd.
When i run the same using terminal it is saying BUILD FAILURE
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.assertpackage.AssertUnitTest
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.055 sec <<< FAILURE!
Results :
Failed tests:
messageTest(com.assertpackage.AssertUnitTest): expected:<ab[c]> but was:<ab[d]>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.712s
[INFO] Finished at: Fri Sep 13 11:36:12 GMT+05:30 2013
[INFO] Final Memory: 9M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire- plugin:2.7.2:test (default-test) on project AssertProject: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/support/Documents/Omniture_Selenium_Project/AssertProject /target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
what is this error and how to resolve it and make BUILD SUCCESS
The standard maven-build will run all tests found in src/test/java and if one of them fails (like your example-test) the build will fail.
So to make the build succeed you have to make all tests pass.
Maven uses the test goal of the surefire plugin to run all unit tests by default and fails even if one test fails. The console output pretty much says so:
Failed to execute goal org.apache.maven.plugins:maven-surefire- plugin:2.7.2:test (default-test) on project AssertProject: There are test failures.
If a goal fails to execute, the outcome is a build failure.
So, just make your test not fail or skip tests for now (not recommended).
The Surefire plugin has a testFailureIgnore parameter which, when enabled, does not cause the build to fail when tests fail.
You could add it on the command line:
mvn install -Dmaven.test.failure.ignore=true
(credit to #PascalThivent)
Or you could bake it right into your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<!-- Build, even if tests fail -->
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
Note that this does not stop the test from being run like others have suggested. The tests are run like normal and all reports are still generated. With this setting it is just no longer required that all tests pass for the project to build. Because of this I tend to include this Surefire configuration in all my poms.
During the build process a certain unit test failed. you can skip the test by adding the ff parameter -Dmaven.test.skip
Maven build lifecycle contains TEST phase which run all jUnit test which belong to project. If test fails build life cycle fails too. This is desirable behavior because you don't want to release application which doesn't pass your tests.
You can fix it by writing test which will pass TEST phase (expected behavior) or you can build application with maven parameter -DskipTests which will skip TEST phase of lifecycle.
* EDIT *
Also I recommended you to look at Docs about maven build life cycle.
Maven proposes three different way to manage failures in reactor builds: fail-fast, fail-at-end and fail-never.
The default way is fail fast, which stops the reactor build after the first failing project. To make BUILD SUCCESSFUL despite of test failures, you can try the fail-at-end policy (using the --fail-at-end (or just -fae) parameter.
Via: Mastering The Maven Command Line – Managing failures

OpenTripPlanner getting started tutorial error

I'm trying to install OpenTripPlanner following the official tutorial.
I've correctly cloned the git repository, then I import the project in Eclipse but it is unable to build all the packages. One of the error is "The import org.geotools cannot be resolved"
So I've tryed with the Maven tutorial but when I run "mvn install integration-test -DskipTests -P interactive" I get:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: org.geotools:library:pom:null
Reason: Cannot find parent: org.geotools:modules for project: org.geotools:library:pom:null for project org.geotools:library:pom:null
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Mon May 20 15:53:31 CEST 2013
[INFO] Final Memory: 44M/473M
[INFO] ------------------------------------------------------------------------
Googling, I've not found anything similar, so, what's the matter?
seems that the geotools.version (and other) properties are not set in the main pom (https://github.com/openplans/OpenTripPlanner/blob/master/pom.xml).
Probably the hudson builder is using variables coming from the settings.xml.
Try defining it manually:
mvn install integration-test -DskipTests -Pinteractive -Dgeotools.version=9.1 -Dspring.version=3.1.1.RELEASE

How to get Jenkins to --fail-fast on Maven 2 builds?

I am trying to build a multi-module Maven project using Jenkins.
When I build the same project on the command-line using the same environment (variables/settings.xml/user) as Jenkins does, test failures cause the build to fail immediately:
Failed tests:
testSomething(com.package_name.TestSomethingOrTheOther)
Tests run: .., Failures: 1, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
...
# Build fails immediately
Where-as when building in Jenkins:
Failed tests:
testSomething(com.package_name.TestSomethingOrTheOther)
Tests run: .., Failures: 1, Errors: 0, Skipped: 0
[ERROR] There are test failures.
...
# Build continues to other modules
...
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] parent ................................................ SUCCESS [.....s]
[INFO] module-that-failed .................................... SUCCESS [.....s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
The build states that all modules and parent are SUCCESS-ful, when in reality, these should be failures.
How do I get Jenkins to enforce fail-fast in maven builds as maven does in the command-line?
Thanks in advance.
Jenkins ignores test failures by default, and then marks the build as unstable if they were any.
The parameter that controls that is: testFailureIgnore (see surefire plugin doc)
I've never tried that, but I would attempt to override that setting on the jenkins job configuration:
-Dmaven.test.failure.ignore=false
You can specify MAVEN_OPTS if you click on Advanced button in the Build section.

Resources