skip the execution of maven-war-plugin - maven-war-plugin

How do I skip the execution of the maven-war-plugin during a mvn command?
Based on the documentation, it seems like I should be able to do so by running something like the following, using -Dmaven.war.skip=true:
mvn verify -P integration-test -Dmaven.war.skip=true
But when I do that the maven-war-plugin still gets executed.
Also strange is that when I remove the maven-war-plugin from my pom altogether, it still gets executed. That leaves me wondering why maven-war-plugin is getting executed at all, as I don't have it mentioned anywhere in my pom.xml.
So maybe a better question is: what brings the maven-war-plugin into the project if I don't have it listed as a plugin?

As it turns out, removing the packaging of my pom to war (<!--<packaging>war</packaging>-->) keeps the maven-war-plugin from executing. The maven-jar-plugin gets executed instead. That's not really what I want (I just want to run integration tests via mvn verify without taking too long). But it runs quicker at least.

You must override the default war execution.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
Explanation
By default, the war goal binds to the package lifecylcle phase as stated in the documentation.
So we override the package execution in the pom with the skip configuration.

You need to override executions configuration of maven war plugin:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webappDirectory>target/stampli-output/</webappDirectory>
</configuration>
<executions combine.children="override">
</executions>
</plugin>
It should do.
Why those instructions?
There is something like super-pom for every pom that has some standard defaults.
These defaults will be merged with your configuration if you don't override them.
Therefore also executions will be merged, which bind plugin goals with phase in mvn.
Links to read:
https://maven.apache.org/ref/3.0.4/maven-model-builder/super-pom.html
https://maven.apache.org/plugins/maven-help-plugin/effective-pom-mojo.html
https://maven.apache.org/pom.html#build - it has info on combine.children
https://maven.apache.org/guides/mini/guide-configuring-plugins.html

Related

Maven not Running Tests Specified in Profile

I've got a vary simple profile in my maven pom file to run some integration tests during the normal test phase. Note I do not want to run these tests during the normal integration-test phase because I do not want to build the war and deploy etc. The tests run fine as normal JUnit tests.
So here is my profile:
<profile>
<id>AdminSeltests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>**/*/TestSellerSignupWizard.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>execution2</id>
<phase>test</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
My test is called:
com.xxxxx.xxx.client.selenium.seller_signup.TestCustomerSignupWizard
However when I run the above profile with:
mvn test -P AdminSeltests
No tests are run. I have tried the following as the value(s):
<include>**/TestSellerSignupWizard.*</include>
<include>**/TestSeller*.*</include>
<include>**/TestSeller*.java</include>
<include>**/*/TestSeller*.java</include>
<include>
com.xxxxx.xxx.client.selenium.seller_signup.TestCustomerSignupWizard.java
</include>
None of these work.
Any ideas anyone?
Thanks
Adam
SOLVED:
I'm using the maven-surefire-plugin and this has a automatic includes section which includes your normal test stuff. So I made an exclude configuration to exclude the normal unit tests, and then an include section to include a patter of integration test that I want to run
Not sure why it works this way, but it does:
<configuration>
<excludes>
<exclude>**/Test*.java</exclude>
<exclude>**/*Test.java</exclude>
<exclude>**/*TestCase.java</exclude>
</excludes>
<includes>
<include>**/ITTestSellerSignupWizard.java</include>
</includes>
</configuration>
Thanks for your help everyone.
The actual piece of code you did paste obviously doesn't work because you're mentioning class TestSellerSignupWizard while having tests in TestCustomerSignupWizard. I assume however it's a typo which doesn't matter actually because one of the Surefire's default mask for inclusion is **/Test*.java that fits well with you in this case.
So it all looks like working solution, so I'm afraid a problem is you don't have this class in your test classpath. You mentioned this is somehow related to integration testing so probably this class is located in src/it/java and not src/test/java that is Maven's default for Surefire. If I'm right, you should move this class into src/test/java or use (as you tried) alternative Surefire execution but with testSourceDirectory parameter overrided (link).

How to display dependency conflicts in 'mvn site'

I can easily see if there are conflicts between (transitive) dependency versions using:
mvn dependency:tree -Dverbose=true
... this will show the full resolution tree, including which elements were omitted (for duplicate or conflict or whatever). What I would like to do is to add the full tree to the 'mvn site' report.
Currently, the site report includes the dependency tree but only as resolved, i.e., without any conflicts. I see in the project-info-reports plugin that there is not currently any way to do what I want using the standard report.
I tried adding a section to the pom to include the maven-dependency-plugin 'tree' goal with the outputFile specified, but it wasn't included when I ran 'mvn site'. It was something like this:
<reporting>
....
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<reportSets>
<reportSet>
<id>deptree</id>
<reports>
<report>tree</report>
</reports>
<configuration>
<verbose>true</verbose>
<outputFile>${project.reporting.outputDirectory}/deptree.txt</outputFile>
</configuration>
Of course, the 'tree' goal is explicitly identified as not a report, but I was hoping to at least be able to produce a file that I could link to from the generated site. No dice.
Is there any way to force an arbitrary plugin's goal to execute during site generation? Am I totally out of luck here? Obviously I could write my own reporting plugin to do this, and/or submit a patch for the project-info-reports plugin, but I want to make sure I've exhausted all the built-in maven options.
(I'm using maven 2.1.0, but I didn't see anything about a change to this functionality in the release notes for later versions.)
Is there any way to force an arbitrary plugin's goal to execute during site generation? Am I totally out of luck here?
Just to answer your question, you can bind a mojo to the pre-site phase of the Site Lifecycle:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>tree</id>
<phase>pre-site</phase>
<goals>
<goal>tree</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
...
</reporting>
If you then run mvn site, dependency:tree will run.

Is it possible to single out and run a specific goal bound to a maven phase?

Updated to (hopefully) clarify: If a goal is defined to run during a given phase, is it possible to run the individual goal without running thru all phases. In other words would it be possible to run the antrun:run goal (which is defined as part of the install phase below) without getting dependencies, generate-resources, compiling, testing, package, etc?
I'm using the antrun plugin to create a zip file during the package phase and to delete and copy some files during the install phase. I understand how to run single maven plugin goals, for example: mvn antrun:run. However, is there a way to run a specific execution's goal? Something like mvn antrun:run:execution-id, or mvn phase:antrun:run?
Basically, I'd be nice if I can tell maven to do nothing else but run the ant tasks defined below inside the deploy phase, for example. It's kind of tedious having to wait for maven to go thru all the phases just to check if the ant tasks in the deploy phase are working correctly.
<executions>
<!-- create zip file -->
<execution>
<id>create-zip</id>
<phase>package</phase>
<configuration>
<tasks>
...create zip...
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
<!-- do some other stuff -->
<execution>
<id>copy-files</id>
<phase>install</phase>
<configuration>
<tasks>
...delete some files, copy some files ...
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
In other words would it be possible to run the antrun:run goal (which is defined as part of the install phase below) without getting dependencies, generate-resources, compiling, testing, package, etc?
No it's not. While you can configure a plugin (with a <configuration> section under the <plugin> element) and call in on the command line, you can't invoke a specific executionid (and consequently the <configuration> specific to an <execution>).
The only solution in your case would be to declare the antrun plugin in a profile, let's say my-profile, to duplicate the following part of the configuration to configure the plugin in this profile:
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
<configuration>
<tasks>
... delete some files, copy some files ...
</tasks>
</configuration>
</plugin>
and to call with the right active profile:
mvn antrun:run -Pmy-profile
Try the exec maven plugin...
For ex:
When you run jboss with maven, you can't see the jboss console output, but I need it to display, so what I did is I wrote a java file that reads in server.log(the server console output) as it changes to display the changes so it appears that jboss console is actually showing(a bit hack-ish but working). So I come to the point of answering your question, during the pre-integration-test I executed a java goal which starts my java program. Here is how , using execute plugin of course :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<id>console-start</id>
<phase>pre-integration-test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.eclipse.console.Main</mainClass>
</configuration>
</plugin>
You just run the install and it executes during the pre-integration-test, however if you just want to execute something like java, use the execute plugin. Sorry if the answer not appropriate, I didn't have the patience to read your question in details, my work hours are over .. cheers

Checkstyle not working

I am new to maven and chekstyle, so need to ask some question... I want to use checkstyle in my maven based project, so in my pom.xml I have add the dependency
<dependency>
<groupId>checkstyle</groupId>
<artifactId>checkstyle</artifactId>
<version>2.4</version>
</dependency>
and also I have added the entry in plugin tag:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.4</version>
<configuration>
<enableRulesSummary>true</enableRulesSummary>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
But when I run my maven build with command mvn clean install, checkstyle doesn't do anything. And as I dont have any checkstyle.xml in my system yet, shouldn't it complains me about the error?
What else configuration am I missing?
I want to use checkstyle in my maven based project, so in my pom.xml I've add the dependency (...)
You don't need to add this dependency, you just need to declare the plugin (a plugin declares its own dependencies).
(...) But when I run my maven build with command mvn clean install, checkstyle doesn't do anything.
Yes because you only declared the plugin, you did not bind the check goal to a lifecycle phase, so a normal build doesn't trigger the checkstyle plugin. If you want checkstyle:check to be triggered as part of your build, you need to declare the check goal inside an execution (it binds itself by default to the verify phase). Something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<!-- Lock down plugin version for build reproducibility -->
<version>2.5</version>
<configuration>
<consoleOutput>true</consoleOutput>
<configLocation>checkstyle.xml</configLocation>
...
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Now, calling any phase including verify will invoke checkstyle.
And as I don't have any checkstyle.xml in my system yet, shouldn't it complains me about the error?
It will... when called (either explicitly by mvn checkstyle:check or as part of the build if you modify your setup as suggested).

Maven2: How to stage JXR plugin result when using mvn site?

I have a multi-module project and I want to deploy on the project's site an HTML version of my source code using the JXR maven plugin.
The problem is that the JXR plugin runs well, the XREF folder is properly generated for each of my module, but when I use the mvn site:stage command in order to retrieve all the project's site content and to have all link properly generated it does not retrieve the XREF folders.
Here is an extract of my POM file where the JXR plugin is configured:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jxr-maven-plugin</artifactId>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
Here is the command I use to create and stage my site:
mvn site site:stage
Do you guys have any idea?
Thanks in advance.
r.
Not sure this is relevant, but your command is running the site twice, mvn site will generate the site, and site:stage will also run the site, perhaps this is causing problems but I honestly can't see why.
Looking at the JXR documentation, it only mentions the site:site goal, I can't see why it wouldn't be run properly for the site:stage goal as it extends it. If you run the site goal, then copy the output to another directory, run the site:stage goal and compare the output it might give some insight into the problem.
Update: I tried this myself and the xref was included and aggregated nicely in c:\test\stage with the cross references correctly managed. I've included the configuration I used.
In my parent pom I defined the site configuration like this:
<build>
<plugins>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>stage</goal>
</goals>
</execution>
</executions>
<configuration>
<stagingDirectory>c:\test\stage</stagingDirectory>
</configuration>
</plugin>
</plugins>
</build>
The distributionManagement section was configured with the site information (not really needed as I set the stagingDirectory above, but the goal won't run without it).
<distributionManagement>
<site>
<id>mojo.website</id>
<name>Mojo Website</name>
<url>scp://test/</url>
</site>
</distributionManagement>
My JXR configuration in the parent pom was as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<reportSets>
<reportSet>
<id>src-xref</id>
<reports>
<report>jxr</report>
</reports>
</reportSet>
<reportSet>
<id>test-xref</id>
<reports>
<report>test-jxr</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<aggregate>true</aggregate>
</configuration>
</plugin>
The commandline run was mvn clean site:stage
Edit: Per the comments, there is a codehaus jxr plugin with slightly different semantics. Be sure to use the org.apache.maven.plugins version rather than the org.codehaus.mojo version.