How do you debug Maven plugin tests executed with the maven-invoker-plugin? - maven

I would like to attach to some tests for a Maven plugin being executed with the maven-invoker-plugin. How does one do this? I can't seem to find any resources and it doesn't seem to be by simply doing:
MAVEN_OPTS="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9001" mvn clean install
I mean -- I can connect this way, but when the maven-invoker-plugin starts, it just sits there. Forever...
Any help would be appreciated.

You must be aware that maven-invoker-plugin invokes a separate instance of Maven for running integration tests like a manual call of mvn with the appropriate configuration options. That's the reason why maven sticks...
You can put the appropriate options into invoker.mavenOpts or into a invoker.properties file.
An other option would be to change the mavenExecuteable and use mvnDebug instead of mvn.

Apparently, (after further inspectiong of the build.log) with the above mentioned way, it freezes simply because Maven is waiting for you to connect with a remote debugger a second time -- this time for the forked process.

Related

FitNesse: Could not invoke constructor for SeleniumDriverSetup[0]

So, I've successfully completed the installation of IntelliJ using hsac-fitnesse-fixtures installation guide.
Next I've set up a project, added the IntelliJ Idea Fitnesse plugin, added a Maven configuration.
FitNesse runs correctly, ending with Starting FitNesse on port: 9090
Next I try to run a test on a test environment, but that fails.
The 1st failure is:
Could not invoke constructor for SeleniumDriverSetup[0]
The 2nd failure is:
The instance scriptTableActor.startDriverFor. does not exist
This is an HSAC environment.
I'm sorry I did not see you question earlier.
It appears I did not update the installation guide when making a change to how the wiki should be started from the IDE. I only updated the project's README.
Anyway the problems lies it the command used in the maven configuration the guide instructed you to make. The Maven command has to be compile dependency:copy-dependencies exec:exec and the guide missed the 'dependency:copy-dependencies' part. Using compile dependency:copy-dependencies exec:exec should fix your problem.

Run dynamic web project with maven in debug mode

I built a dynamic web project with tomcat7 server on maven. To test the project I run mvn tomcat7:run every time anything is changed. This seems to time consuming.
Is there any way to run this in debug mode so I don't have to run project every time I change something in files? mvn --debug doesn't seem to work.
You can use JRebel.
See the answer to this question from stackoverflow for configuring maven with JRebel.
use mvnDebug for debugging/breakpoints.
Otherwise if any class change yup you have to restart (in order to recompile)

Maven javadoc plugin should be skipped by default but should able to execute when needed

I want maven-javadoc-plugin to be skipped by default, during the
mvn clean install command, so I have added <skip>true<skip> in the pom.xml
But I want it to be executed whenever needed, so I am trying something like
mvn clean install -Dmaven.javadoc.skip=false But it seems that it is overriding this setting with that in pom.xml and not executing the javadoc plugin.
What can I do to resolve this problem?
You could create a profile for the plugin execution (move it from the normal build generation). Within the profile, simply state that the plugin should run when you want it. The idea is that when you do a run without the profile included in arguments, it won't run; if you include the profile argument, it'll be kicked off:
http://maven.apache.org/guides/introduction/introduction-to-profiles.html
Run arguments would look something like:
mvn groupId:artifactId:goal -P profile-1

Maven plugin execution change Maven properties or skip build lifecycle steps

When I build my application with maven, I run mvn clean install. As a part of the install lifecycle, I run appengine:devserver_start from Google's GAE Maven plugin. This appears to be already bound to a step in the lifecycle and therefore it reruns some build steps from the beginning, even though me running mvn install did those. For example, the resources step is rerun. I had my own Java script run to download the latest resources for my build. But because of appengine:devserver_stop, I need to uselessly run this cript again because the resources step is re-executed.
I can think of two ways I can avoid this, but I'm not sure how to configure both ways. The first would be to somehow skip re-running build steps that I've already run. The other way would be to change the Maven POM properties just for the plugin execution. I have a Maven property set, either to true or false, that I can use to set the skip setting for the Java script I use during resources (because I run this script using the exec-maven-plugin). Think of this as a Maven property that can be set with the -D flag. Can I have this property changed just for the plugin?
If you are having trouble thinking about my scenario, consider what happens when you run mvn compile install. All build lifecycle steps until compile will run, then all compile steps until install will run, including compile.
A common/easy way to solve this kind of problems is to use maven profile. Just create a new profile that includes the plugin with preferred phases.
You should probably don't fight with it and just run clean appengine:devserver_start instead of clean install. Read my answer here for a more detailed explanation:
https://stackoverflow.com/a/17638442/2464295

Debug a maven plugin's execution in a maven web-project

Is there any way to actually debug a maven plugin while it is in action. What I mean is that for example we have the maven-clean-plugin. So when this plugin executes it's action can we somehow debug and check inside the source code of maven-clean-plugin?
Obviously we would have to associate the Java source for the plugin in eclipse but how can we set it for debugging?
Thanks.
EDIT: Changing the subject
I'm sorry guys maybe I should have been more precise. Actually I have my web-app which is a maven project, which makes use of 3rd party maven plugins. Now when I do a mvn clean install I need to debug my 3rd party maven plugin. Now in my maven dependency I dont get a dependency to that plugin jar, which is quite normal. Any ideas?
If you are using Eclipse with the m2eclipse plugin, simply launch your build with Debug As... instead of Run as....
If you are not using m2eclipse, run mvnDebug instead of mvn (for Maven 2.0.8+) and attach a remote debugger on port 8000. For Maven 2.0.8<, add the remote debuggin options to the start script.
Of course, you need to import the sources of the plugin in your workspace.
See also
Developing and debugging Maven plugins
Dealing with Eclipse-based IDE
If you want to debug Maven execution in eclipse, here is how I did it, with mostly command-line tools (no Eclipse plugin used) (may be off at some points, I haven't done that for 6 months):
Run, from the command line, mvndebug in place of the mvn command. Maven will begin launching and wait for an external debugger to appear on a TCP port before resuming. Note the port number.
Configure in Eclipse a custom, remote debug configuration. (See http://www.ibm.com/developerworks/library/os-ecbug/ , Remote debugging) - set the port number as the one used by mvndebug. Also put the source files that you will be using for debugging in the Debug configuration.
Launch the remote debug configuration. Maven should resume and you will catch bugs in Eclipse.
This might be slightly off, since I'm going to talk about IntelliJ IDEA. With IDEA, you can load a maven project directly, and then simply right click on one of the build lifecycle phases (clean, package, install etc...) and choose debug. The IDE then runs that phase with the correct classpath and drops you into a debugger.
I've used the debugger to debug several of my own plugins. I've never tried debugging a third party plugin, although I imagine this will be relatively painless if the jar still has debug symbols in it and you have corresponding source code.
The community edition of IDEA is available for no fee.
Just replace mvn with mvnDebug in your command:
mvnDebug clean install
As result JVM listens for debugger at port 8000. For finer control you can set MAVEN_OPTS environment variable with standard JVM debug parameters:
export MAVEN_OPTS="-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000"
mvn clean install
In NetBeans 7.4, Right-click the project > Properties > Actions. Pick the Build project action (or any other), then next to "Set Properties" click Add and Debug Maven Build.

Resources