How do you build a Maven project without running unit tests?
Currently restructuring some code I have for a Servlet and would like to try it out in my web browser (which means running mvn install to get the .war to upload to Tomcat). I'm fully aware my UNIT tests are failing and I'm fine with that because I will fix it once I have the code the way I want. Can anyone advise?
If you want to skip running and compiling tests:
mvn -Dmaven.test.skip=true install
If you want to compile but not run tests:
mvn install -DskipTests
If you are using eclipse there is a "Skip Tests" checkbox on the configuration page.
Run configurations →
Maven Build →
New →
Main tab →
Skip Tests
Run following command:
mvn clean install -DskipTests=true
With Intellij Toggle Skip Test Mode can be used from Maven Projects tab:
mvn clean install -Dskiptests=true
Now, the only difference from the answers above is that the "T" is in lower case.
I like short version: mvn clean install -DskipTests
It's work too: mvn clean install -DskipTests=true
If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin.
mvn clean install -Dmaven.test.skip=true
and you can add config in maven.xml
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>
If you call your classes tests Maven seems to run them automatically, at least they did for me. Rename the classes and Maven will just go through to verification without running them.
Related
How do we integrate release plugin with clean install. Currently we execute clean install -Pprofile,autoInstallPackage to build and deploy the package to the environment after changing the SNAPSHOT version to release version in pom.xml.
We wanted to enhance the release process which includes updating pom with release version -> deploy using install profile -> creating a new Development Version.
for which clean install release:prepare -Dresume=false -DreleaseVersion=3.2 -Dtag=3.2 -DdevelopmentVersion=3.3 works as well without deployment to environment.
I have problem in executing
`clean install -Pprofile,autoInstallPackage release:prepare -Dresume=false -DreleaseVersion=3.2 -Dtag=3.2 -DdevelopmentVersion=3.3`
this deploys a SNAPSHOT version rather than release version which makes sense as I don't have a proper sequence.
However, Using the below command doesn't work either:
clean \
release:prepare -Dresume=false -DreleaseVersion=3.2 -Dtag=3.2 \
install -Pprofile,autoInstallPackage \
release:prepare -DdevelopmentVersion=3.3
this is trying to execute git tag twice and fails. Still deploys the 3.2-SNAPSHOT version.
Did you try preparationGoals in the Maven-Release-Plugin section of your pom.xml?
To run additional goals after release preparation but before committing, specify them using the preparationGoals property.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<preparationGoals>clean install</preparationGoals>
</configuration>
</plugin>
These maven goals are executed after the release is prepared, but prior to the submission of the release into source control.
The maven release goals are executed in this order:
release:prepare
preparationGoals
release:perform
completionGoals
Also, take a look at this post and see if it also relates to your question.
In jetty-9 the mvn jetty:deploy-war fails to start the web application. Maven just ends the build, while I expect it to block with a running jetty server. According to the logging output the jetty maven plugin does start a connector on port 8080, and it starts the WebAppContext. It seems to fail binding the port to the context though.
Steps to reproduce:
Create a web app: mvn archetype:generate -DinteractiveMode=false -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=jetty -DartifactId=jetty-demo
Add this plugins-section to the pom:
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.10.v20150310</version>
</plugin>
</plugins>
...
</build>
Execute:
mvn package
mvn jetty:deploy-war This should start the web app and then block, but it just ends the build
Using jetty-8 all works fine:
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
Note: mvn jetty:run-war works as expected in jetty 9. This is the same as deploy-war, but it triggers jetty to build the war before deployment
Reference: the jetty-9 maven plugin manual. And I debugged the jetty startup proces, but without luck so far.
The documentation you linked to tells you why.
Set the daemon parameter to false and it will block
Related to
eclipse debug remote web application => How do I debug a remote application in my eclipse
How can I set / archive this in the mvn tomcat plugin?
http://tomcat.apache.org/maven-plugin-2.0-SNAPSHOT/tomcat7-maven-plugin/
The only thing that might help is setting systemProperty but that doesn't work for me ;/
Goal: let tomcat run on console via maven but enable remote debugging for different IDEs
(YES guys, we can run tomcat in Eclipse WTP! That's not the question ;)
$ export MAVEN_OPTS=-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n
$ mvn tomcat7:run-war
^^ that's it, not cool (as it is not in POM) but it works
Source: http://aaronz-sakai.blogspot.de/2009/02/debugging-jetty-when-running-mvn.html
It's a bit old thread but for the sake of completeness I though i might add a little here.
The plugin does not provide debug options configuration for whatever strange reason.
Thus your only option is to manually specify debug configuration to the JVM that runs the process.
In your environment, there are three ways achieve this:
Using a well known-maven environment variable (as described by childno.de)
Directly specifying the options to maven (no env. variable needed):
mvn -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y tomcat7:run-war
With an eclipse Run configuration That's basically the same like 2) but you define this in eclipse (that would be good if you didn't want to leave the IDE at all).
To achieve that you need to specify a Maven Build Run configuration.
Set the goal to tomcat7:run (or similar) and then navigate to the JRE tab. The VM arguments area is where you specify the debug configuration: -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y
If you opt for 3), the precise run goal for tomcat7 is irrelevant to the debug enabling. Choose according to you use case (dynamic web project, war, etc.). Same goes for the plugin configuration. However, make sure to specify that you are using the tomcat maven plugin in the pluginManagement section of your project pom:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</pluginManagement>
OR... you could simply add the following tag to your plugin configuration
<jpda>true</jpda>
Then when you execute: mvn tomcat7:run, it will start jpda on port 8000.
Funny thing is even though I have tested this and it works, I can't find any code in the opensource code base to explain why it works, nor have I found any way to change from the default port 8000.
Apache seems to have dropped the ball when it comes to documentation of this plugin.
I want to use Jetty 8.0 Server for my application. Which IDE i will use for simple configuration.
Presently i am using Eclipse. How to configure jetty in Eclipse. Any best example?
I use run-jetty-run, and jetty with maven in eclipse.
http://code.google.com/p/run-jetty-run/
More on jetty maven plugins:
http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
I use run-jetty-run with DCEVM for hotdeploy.
Here's my tutorial, Spring-mvc + Velocity + DCEVM
Most people I know simply write a small embedded usage of jetty for their application. It is dead simple to do and there are a number of examples in the example-jetty-embedded project in jetty git repository. It is also how most of our test cases are written, using jetty itself to test.
http://git.eclipse.org/c/jetty/org.eclipse.jetty.project.git/tree/example-jetty-embedded
If your using maven then the jetty-maven-plugin is a pretty simple way of testing and works with the eclipse plugin Webby which streamlines much of the pain and suffered that is called WTP.
https://docs.sonatype.org/display/M2ECLIPSE/Integration+with+Maven+WAR+Plugin
There is also a Jetty WTP plugin that many people use successfully.
http://wiki.eclipse.org/Jetty_WTP_Plugin
I also use run-jetty-run for Eclipse.
I tried the Jetty plugin for NetBeans, but it didn't work.
I think Jetty for Eclipse is better than Tomcat, cause its simpler to use and configure and a fast server.
Assuming you have setup M2Eclipse plugin within Eclipse correctly and your project is configured to use Maven, I've found Jetty Maven Plugin within Eclipse to be particularly useful. The beauty of this approach is that you can do your development really fast, especially if you have 3rd party dependencies. All you have to do is add the following plugin to your pom.xml:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.8.v20121106</version>
<configuration>
<contextPath>/</contextPath>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
To use this plugin successfully here some additional notes on installation and usage:
Eclipse Integration
Install the following Eclipse Plugins first
Maven Integration for Eclipse (Help > Eclipse Marketplace...)
A patch that makes it possible to debug source code at runtime. Eclipse Plugin Link
Next, create a "Maven Build" Eclipse Launcher
You also need to configure "Maven Build" launcher so that you can run the Jetty Server quickly. Follow the instructions below create this launcher:
Right-click on your current project and select (Run As/Debug As) > Maven Build...
Set Goals As rhubarb:start
Check Resolve Workspace artifacts
Save
Going forward, you can simply do: (Run As/Debug As) > Maven Build, and the goal will execute.
I am trying to debug Maven tests in IntelliJ IDEA. When I open IDEA's Maven Projects view and right-click on test goal, I get an option to debug it. Clicking it executes this goal but the execution never stops at any breakpoints. What am I missing?
Thanks.
Just disable the forked mode - something like this in your pom file (under project/build/plugins section):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14</version>
<configuration>
<forkMode>never</forkMode>
</configuration>
</plugin>
One solution would be to use remote debugging:
configure the surefire plugin: <debugForkedProcess>true</debugForkedProcess>;
run the test (will wait for a remote debugger to connect)
create and run a remote debug configuration in IntelliJ (will hit your breakpoint); the port to connect to is 5005.
If you're running unit tests with maven failsafe rather than surefire, then debugger will not stop and you have to manually run a failsafe debugger command line and then intellij will be able to stop on the breakpoints. I am unsure if using <forkMode>never</forkMode> option on failsafe solves this issue.
As I describe here: https://github.com/djangofan/maven-failsafe-debug-example
Your sources for the dependencies do not match the binary code. Make sure you're using the same sources.