Maven `pre` and `post` phases - maven

Are the pre and post phases always executed when I execute the associated phase? For example, if I do mvn clean, will this execute the mvn post-clean phase, too?
I was looking at https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Lifecycle_Reference, in which it said:
The following lists all build phases of the default, clean and site
lifecycles, which are executed in the order given up to the point of
the one specified.
So strictly speaking, since post-clean comes after clean, it should not be executed if I just do mvn clean. But my gut feel is different - although, I didn't find a way to verify this, as the maven stdout doesn't print the phase it's executing.
Could anyone weigh in on the answer and how you verified?

You can bind a plugin (such as echo-maven-plugin) to the phases of the clean lifecycle to help verify if/when each phase is executed.
For example, given the following plugin definition:
<plugin>
<groupId>com.github.ekryd.echo-maven-plugin</groupId>
<artifactId>echo-maven-plugin</artifactId>
<version>1.2.0</version>
<executions>
<execution>
<id>pre-clean</id>
<phase>pre-clean</phase>
<goals>
<goal>echo</goal>
</goals>
<configuration>
<message>In 'pre-clean'</message>
</configuration>
</execution>
<execution>
<id>clean</id>
<phase>clean</phase>
<goals>
<goal>echo</goal>
</goals>
<configuration>
<message>In 'clean'</message>
</configuration>
</execution>
<execution>
<id>post-clean</id>
<phase>post-clean</phase>
<goals>
<goal>echo</goal>
</goals>
<configuration>
<message>In 'post-clean'</message>
</configuration>
</execution>
</executions>
</plugin>
Invoking mvn clean will result in the following output:
$ mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] --- echo-maven-plugin:1.2.0:echo (pre-clean) # sandbox ---
[INFO] In 'pre-clean'
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # sandbox ---
[INFO] Deleting target
[INFO]
[INFO] --- echo-maven-plugin:1.2.0:echo (clean) # sandbox ---
[INFO] In 'clean'
So, there's no invocation of the post-clean phase there.
Invoking mvn clean compile will result in the following output:
$ mvn clean compile
[INFO] Scanning for projects...
[INFO]
[INFO] --- echo-maven-plugin:1.2.0:echo (pre-clean) # sandbox ---
[INFO] In 'pre-clean'
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # sandbox ---
[INFO]
[INFO] --- echo-maven-plugin:1.2.0:echo (clean) # sandbox ---
[INFO] In 'clean'
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # sandbox ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) # sandbox ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to ...
Again, there's no invocation of the post-clean phase there. This implies that the maven-clean-plugin (and perhaps nothing else) is not bound to post-clean.
Invoking mvn post-clean will result in the post-clean phase being invoked ...
$ mvn post-clean
[INFO] Scanning for projects...
[INFO]
[INFO] --- echo-maven-plugin:1.2.0:echo (pre-clean) # sandbox ---
[INFO] In 'pre-clean'
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # sandbox ---
[INFO] Deleting target
[INFO]
[INFO] --- echo-maven-plugin:1.2.0:echo (clean) # sandbox ---
[INFO] In 'clean'
[INFO]
[INFO] --- echo-maven-plugin:1.2.0:echo (post-clean) # sandbox ---
[INFO] In 'post-clean'
So, based on the above test I think the following statements are true:
post-clean is not invoked when you call clean
post-clean is only called when you explicitly invoke post-clean (note: invoking the pre- and post- phases directly is unusual)

Related

Jaxb2 maven plugin : Sources vs SchemaDirectory

I am making a maven project that will make use of Jaxb2-maven-plugin to generate java files out of xsd files. My Project structure is like:
project.basedir
--src/main/resources/schemas
----common
----request
----response
Below is the plugin config from pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>xjc-PDF</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<extension>true</extension>
<clearOutputDir>false</clearOutputDir>
<outputDirectory>${project.build.directory}/generated-sources/jaxb</outputDirectory>
<explicitAnnotation>true</explicitAnnotation>
<!-- <schemaDirectory>${project.basedir}/src/main/resources/schemas</schemaDirectory> -->
<sources>
<source>${project.basedir}/src/main/resources/schemas/common</source>
<source>${project.basedir}/src/main/resources/schemas/response</source>
<source>${project.basedir}/src/main/resources/schemas/request</source>
</sources>
<bindingDirectory>${project.basedir}/src/main/resources/schemas</bindingDirectory>
<!-- <bindingDirectory>${project.basedir}/src/main/resources/bindings</bindingDirectory> -->
<bindingFiles>jaxb-bth.xjb</bindingFiles>
</configuration>
</execution>
</executions>
</plugin>
If I compile like this then I get below error (even though the source directories contains valid schema files):
C:\ESB_SOAP5_Space\pdf-util>mvn clean install
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building pdf-util 1.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # pdf-util ---
[INFO] Deleting C:\ESB_SOAP5_Space\pdf-util\target
[INFO]
[INFO] --- build-helper-maven-plugin:1.6:add-source (add-source) # pdf-util ---
[INFO] Source directory: C:\ESB_SOAP5_Space\pdf-util\target\generated-sources\jaxb added.
[INFO]
[INFO] --- jaxb2-maven-plugin:1.6:xjc (xjc-PDF) # pdf-util ---
[INFO] Generating source...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.205 s
[INFO] Finished at: 2018-03-19T06:27:02+11:00
[INFO] Final Memory: 8M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc (xjc-PDF) on project pdf-util: No schemas have been found -> [Help 1]
However, if I comment sources and uncomment and modify like below, then I am able to generate java classes out of schemas under common.
<schemaDirectory>${project.basedir}/src/main/resources/schemas/common</schemaDirectory>
Can anyone tell me why is this behaving like this? Also what do I do if I have to parse all the schema files under one root folder ( which has multiple child folders)?
Thanks
Version 1.6 of the plugin does not support "sources" tag. You can use "sources tag on version 2.4 or newer.
If you have multiple directories containing xsds, use multiple executions in your configuration with each schemaDirectory pointing to one of your directories.

How to avoid duplicate forking when generating aggregated javadoc in a multimodule project

I am trying to configure a Maven multimodule project to produce a distribution zip via the assembly plugin, which should include aggregated javadoc for all submodules in the project.
The project structure is (simplified, in reality there's about 20 modules):
Project X Core
+- pom.xml (1)
+- module-A
| +- pom.xml (2)
+-module-B
| +- pom.xml (3)
+-assembly
+- pom.xml (4)
where assembly is the submodule that produces the distribution zip. The root pom lists all submodules as modules, each submodule's pom has, in turn, the root pom as its parent. The assembly plugin is bound to the package phase. All of this works fine.
The problem occurs when I try to create aggregated javadoc (not javadoc jars, but a directory with html), to include in the assembly. To achieve this, I have configured the maven-javadoc-plugin as a build plugin in the root pom, as follows:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<source>1.6</source>
<encoding>utf8</encoding>
<quiet>true</quiet>
<links>
<link>http://docs.oracle.com/javase/6/docs/api/</link>
</links>
</configuration>
<executions>
<execution>
<id>create-javadoc</id>
<phase>package</phase>
<goals>
<goal>aggregate</goal>
</goals>
</execution>
</executions>
</plugin>
In addition, I have configured my assembly descriptor, in the assembly submodule, to include a fileSet with the javadocs, picked from the target dir of its parent project:
<fileSet>
<directory>../target/site/apidocs</directory>
<outputDirectory>docs/apidocs</outputDirectory>
</fileSet>
The problem I face with this setup is this: I see the following output when running mvn package:
[INFO] Reactor Build Order:
[INFO]
[INFO] Project X Core
[INFO] Project X: module A
[INFO] Project X: module B
[INFO] Project X: assembly
[INFO] ------------------------------------------------------------------------
[INFO] Building Project X Core 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) # projectX-core ---
[INFO]
[INFO] --- animal-sniffer-maven-plugin:1.13:check (default) # projectX-core ---
[INFO] Checking unresolved references to org.codehaus.mojo.signature:java16:1.0
[INFO]
[INFO] >>> maven-javadoc-plugin:2.10.1:aggregate (create-javadoc) > generate-sources # projectX-core >>>
[INFO]
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X Core 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) # projectX-core ---
[INFO]
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X: module A 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) # projectX-modA ---
[INFO]
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X: module B 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) # projectX-modB ---
Downloading: https://example.org/repositories/snapshots/org/example/project/projectX-modB/1.0.0-SNAPSHOT/modB-1.0.0-20141121.022310-7.jar
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X: Assembly 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Downloading: https://example.org/repositories/snapshots/org/example/project/projectX-modC/1.0.0-SNAPSHOT/maven-metadata.xml
2/2 KB
(snip for brevity)
[INFO] ------------------------------------------------------------------------
[INFO] Building Project X: module A 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) # projectX-modA ---
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) # projectX-modA ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jeen/Projects/projectX/modA/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # projectX-modA ---
[INFO] Compiling 52 source files to /Users/jeen/Projects/projectX/modA/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) # projectX-modA ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/jeen/Projects/projectX/modA/util/src/test/resources
[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) # projectX-modA ---
[INFO] Building jar: /Users/jeen/Projects/projectX/modA/target/modA-1.0.0-SNAPSHOT.jar
[INFO]
[INFO] >>> maven-javadoc-plugin:2.10.1:aggregate (create-javadoc) > generate-sources # projectX-modA >>>
[INFO]
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X Core 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) # projectX-core ---
[INFO]
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking Project X Module A 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO]
[INFO] --- maven-enforcer-plugin:1.0:enforce (enforce-maven) # projectX-modA ---
[INFO]
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[INFO] Forking ProjectX Module B 1.0.0-SNAPSHOT
[INFO] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.....
This is just a snippet, but these "Forking" messages are repeated a great number of times for each submodule (in fact, in reality about 60 times per module). This worries me: it looks as if there is an awful lot of duplicate work going on. A second thing that worries me is that it apparently downloads remote snapshots of artifacts that are part of the current reactor (see the 'Downloading' messages in the snippet above). I should point out that despite all these duplicate messages, the goal is achieved: the aggregate javadoc is produced, and is included in the assembly.
So, the question is really: what (if anything) am I doing wrong? Should I just ignore these repeating "Forking" messages and the snapshot downloads, or are they an indication of an incorrect setup? If the latter, does anybody have an idea how I should tweak the setup to get this to work correctly?
FWIW I have already tried several alternative configurations, including moving the javadoc plugin config to the assembly submodule, but none of it gave me the expected results.
I've tried to keep it brief and to the point, if additional info is needed let me know.
Running Maven 3.2.3, by the way.
I seem to have found the answer to my own question.
The problem is in the javadoc plugin configuration. Because the plugin is in the aggregator project's build section, it gets inherited by the submodules (which then each execute it in turn, apparently).
Simply making sure the plugin does not get inherited fixed the issue:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<inherited>false</inherited>
...

How to revert Maven project.build variables after Clover plugin finishes?

I'm attempting to add integration tests to a large Maven project. Here is the desired order of events:
Clean existing artifacts.
Resolve dependencies and build project.
Run unit tests via Surefire plugin.
Fork lifecycle for Clover plugin.
--- Instrument sources using Clover plugin.
--- Modify project.build.directory and project.build.finalName for Clover.
--- Build Clover instrumented project in a new directory.
--- Run Clover instrumented unit tests via Surefire plugin.
--- Check code coverage from Clover instrumented unit tests.
--- Reset project.build.directory and project.build.finalName to original values.
--- End forked lifecycle (Clover only forks through 'test' phase).
Package project as a WAR file.
Locally host project WAR file via Tomcat7 plugin.
Run integration tests against Tomcat7 instance via Surefire plugin.
All of this works as expected except step #9 (hence the question). Instead, the build directory is still set to the Clover version, and the project name has "-clover" appended to it. I've also found that when "MyProject-clover.war" is hosted by Tomcat7 that it does not function as expected (returns a 404 error in the browser).
Even if it did work, We do not need/want Clover instrumentation in the WAR file which we're testing against because the integration tests don't touch any of the production code (it's all Selenium UI stuff under src/test/java which interacts with the locally hosted pages instead of the production code itself).
As mentioned, this is a large project containing hundreds of dependencies and dozens of plugins. I believe the following are relevant to my issue, though I can dig up more if necessary (posting the entire pom file seems unreasonable).
Here's the pom configuration for the Clover plugin:
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-clover2-plugin</artifactId>
<version>3.1.11</version>
<configuration>
<generateHtml>true</generateHtml>
<generateXml>true</generateXml>
<licenseLocation>${basedir}/src/test/resources/clover.license</licenseLocation>
<targetPercentage>92%</targetPercentage>
<excludes>
<exclude>**/mock/*.java</exclude>
<exclude>**/com/mycompany/somestuff/*.java</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>generate-clover-report</id>
<phase>test</phase>
<goals>
<goal>instrument</goal>
<goal>clover</goal>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
Here's the pom configuration for the WAR plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<!--Implementation-Build>${buildNumber}_${timestamp}</Implementation-Build -->
<Build-Time>${timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
Here's the pom configuration for the Tomcat7 plugin:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<ajpPort>8009</ajpPort>
<backgroundProcessorDelay>2</backgroundProcessorDelay>
<configurationDir>${project.build.directory}/tomcat7_plugin</configurationDir>
<contextFile>${CATALINA_HOME}/conf/context.xml</contextFile>
<contextReloadable>false</contextReloadable>
<fork>true</fork>
<hostName>localhost</hostName>
<httpsPort>8443</httpsPort>
<ignorePackaging>false</ignorePackaging>
<jarScanAllDirectories>false</jarScanAllDirectories>
<path>/contentmain</path>
<port>8080</port>
<serverXml>${CATALINA_HOME}/conf/server.xml</serverXml>
<tomcatUsers>${CATALINA_HOME}/conf/tomcat-users.xml</tomcatUsers>
<tomcatWebXml>${CATALINA_HOME}/conf/web.xml</tomcatWebXml>
<useNaming>true</useNaming>
<useTestClasspath>true</useTestClasspath>
<update>true</update>
<warDirectory>${project.build.directory}/${project.build.finalName}</warDirectory>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-war-only</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
Here's the current (desired) behavior when I run "mvn clean install -Dmaven.clover.skip":
[INFO] --- maven-clover2-plugin:3.1.11:check (generate-clover-report) # MyProject ---
[INFO]
[INFO] --- maven-dependency-plugin:2.1:unpack (unpack) # MyProject ---
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes css/*.css and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes scripts/*/*.* and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes images/*.* and excludes:null
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) # MyProject ---
[INFO] Packaging webapp
[INFO] Assembling webapp [MyProject] in [mydir/MyProject/target/MyProject]
[INFO] Processing war project
[INFO] Copying webapp resources [mydir/MyProject/src/main/webapp]
[INFO] Webapp assembled in [2019 msecs]
[INFO] Building war: /mydir/MyProject/target/MyProject.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] >>> maven-source-plugin:2.2.1:jar (default) # MyProject >>>
[INFO]
[INFO] --- maven-dependency-plugin:2.1:copy (default) # MyProject ---
[INFO]
[INFO] --- buildnumber-maven-plugin:1.1:create-timestamp (default) # MyProject ---
[INFO]
[INFO] <<< maven-source-plugin:2.2.1:jar (default) # MyProject <<<
[INFO]
[INFO] --- maven-source-plugin:2.2.1:jar (default) # MyProject ---
[INFO] Building jar: /mydir/MyProject/target/MyProject-sources.jar
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run-war-only (start-tomcat) # MyProject ---
[INFO] Running war on http://localhost:8080/contentmain
Here's the current (undesired) behavior when I run "mvn clean install" (note the paths listed by maven-war-plugin and warning message from maven-source-plugin:
[INFO] --- maven-clover2-plugin:3.1.11:check (generate-clover-report) # MyProject ---
[INFO]
[INFO] --- maven-dependency-plugin:2.1:unpack (unpack) # MyProject ---
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Configured Artifact: com.mycompany:somedependency:?:jar
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes css/*.css and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes scripts/*/*.* and excludes:null
[INFO] Unpacking /mydir/.m2/myrepo/mycompany/somedir/somedependency.jar to mydir/MyProject/target/MyProject with includes images/*.* and excludes:null
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) # MyProject ---
[INFO] Packaging webapp
[INFO] Assembling webapp [MyProject] in [mydir/MyProject/target/clover/MyProject-clover]
[INFO] Processing war project
[INFO] Copying webapp resources [mydir/MyProject/src/main/webapp]
[INFO] Webapp assembled in [1770 msecs]
[INFO] Building war: /mydir/MyProject/target/clover/MyProject-clover.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] >>> maven-source-plugin:2.2.1:jar (default) # MyProject >>>
[INFO]
[INFO] --- maven-dependency-plugin:2.1:copy (default) # MyProject ---
[INFO]
[INFO] --- buildnumber-maven-plugin:1.1:create-timestamp (default) # MyProject ---
[INFO]
[INFO] <<< maven-source-plugin:2.2.1:jar (default) # MyProject <<<
[INFO]
[INFO] --- maven-source-plugin:2.2.1:jar (default) # MyProject ---
[WARNING] NOT adding sources to artifacts with classifier as Maven only supports one classifier per artifact. Current artifact [com.mycompany:MyProject:war:clover:ParentProject-SNAPSHOT] has a [clover] classifier.
[INFO]
[INFO] --- tomcat7-maven-plugin:2.2:run-war-only (start-tomcat) # MyProject ---
[INFO] Running war on http://localhost:8080/contentmain
What can I do to make sure that the {project.build.directory} and {project.build.finalName} values are reset to their original values after Clover has finished executing the maven-clover2-plugin:check goal during the test phase of the forked lifecycle?
I've already tried browsing the online manuals for Clover, the WAR plugin, and Tomcat7. I see no mention of any settings I can use to revert the build variables that are altered by Clover. I can always hard-code the paths in my pom file, but I'd prefer a less brittle solution.
[INFO] --- maven-source-plugin:2.2.1:jar (default) # MyProject ---
[WARNING] NOT adding sources to artifacts with classifier as Maven only supports one classifier per artifact. Current artifact [com.mycompany:MyProject:war:clover:ParentProject-SNAPSHOT] has a [clover] classifier.
This is a limitation of Maven. It does not support artifacts with multiple classifiers. As the artifact in a forked life cycle has the "clover" classifier already, it cannot have "source" classifier at the same time. That's why this warning is present. You may consider using the clover2:setup instead of the clover2:instrument if you need to call a maven-source-plugin.
4. Fork lifecycle for Clover plugin.
--- End forked lifecycle (Clover only forks through 'test' phase).
There are two Clover goals which forks a build:
clover2:instrument - forks a build till the 'install' phase
clover2:instrument-test - forks a build till the 'test' phase
You may be interested in the latter one. You may also be interested in using the useCloverClassifier=false option - this will disable usage of the "clover" classifier in a forked build.
I've also found that when "MyProject-clover.war" is hosted by Tomcat7 that it does not function as expected (returns a 404 error in the browser).
My first guess is that you have clover.jar (com.atlassian.clover:clover) missing at runtime. You have to either copy clover.jar to Tomcat's /lib directory or to bundle it in your WAR. See https://confluence.atlassian.com/display/CLOVER/Using+Clover+for+web+applications
It turns out that Clover will always alter these variables unless the clover2:setup target is used. However, if you still wish to fork the lifecycle for Clover (IE: clover2:instrument or clover2:instrument-test) then these variables will always be altered.
We wish to continue forking the lifecycle using clover:instrument-test, so I've come up with a workaround. Instead of using the project.build.finalName and project.build.directory variables, I'm using my own variables that get copied and saved on Maven execution before Clover can mess with them:
<properties>
<!-- Saving these variables now before Clover alters them -->
<original.build.finalName>${project.build.finalName}</original.build.finalName>
<original.build.directory>${project.build.directory}</original.build.directory>
</properties>
I then tell all of the subsequent plugins to use these variables instead of the project variables which Clover has altered:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<cacheFile>${original.build.directory}/war/work/webapp-cache.xml</cacheFile>
<outputDirectory>${original.build.directory}</outputDirectory>
<warName>${original.build.finalName}</warName>
<webappDirectory>${original.build.directory}/${original.build.finalName}</webappDirectory>
<workDirectory>${original.build.directory}</workDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<configurationDir>${original.build.directory}/tomcat7_plugin</configurationDir>
<warDirectory>${original.build.directory}/${original.build.finalName}</warDirectory>
</configuration>
</plugin>
</plugins>
Alternative solutions might include creating or utilizing an additional plugin in a subsequent Maven phase to revert the project.build variables after Clover has finished executing. Either of these solutions is probably better than hard-coding the paths in all of your plugins.

exec-maven-plugin does not run on jenkins

Could anyone help me with this,
My jasmine javascript unit tests run successfully when i build my app in eclipse:
[INFO] --- maven-install-plugin:2.3.1:install (default-install) # sig ---
[INFO] Installing C:\Users\C5168279\git\smsigcom.sap.solman.graphical.component.sig\SMSIG\target\sig.war to C:\Users\C5168279\.m2\repository\com\sap\solman\graphical\component\sig\1.0.0\sig-1.0.0.war
[INFO] Installing C:\Users\C5168279\git\smsigcom.sap.solman.graphical.component.sig\SMSIG\pom.xml to C:\Users\C5168279\.m2\repository\com\sap\solman\graphical\component\sig\1.0.0\sig-1.0.0.pom
[INFO]
[INFO] --- exec-maven-plugin:1.2.1:exec (default-cli) # sig ---
2014-02-20 17:35:35 Device API logging initialized - DEVICE
2014-02-20 17:35:35 registerResourcePath ('', 'https://sapui5.hana.ondemand.com/resources/') - sap.ui.ModuleSystem
2014-02-20 17:35:35 URL prefixes set to: - sap.ui.ModuleSystem
2014-02-20 17:35:35 (default) : https://sapui5.hana.ondemand.com/resources/ - sap.ui.ModuleSystem
XMLHttpRequest cannot load https://sapui5.hana.ondemand.com/resources/sap/ui/controller/library-preload.json. Origin file:// is not allowed by Access-Control-Allow-Origin.
2014-02-20 17:35:37 failed to preload 'sap.ui.controller.library-preload': Error: NETWORK_ERR: XMLHttpRequest Exception 101 - sap.ui.ModuleSystem
XMLHttpRequest cannot load https://sapui5.hana.ondemand.com/resources/sap/ui/controller/library.js. Origin file:// is not allowed by Access-Control-Allow-Origin.
Error: failed to load 'sap/ui/controller/library.js' from https://sapui5.hana.ondemand.com/resources/sap/ui/controller/library.js: 0 - Error: NETWORK_ERR: XMLHttpRequest Exception 101
file:///C:/Users/C5168279/git/smsigcom.sap.solman.graphical.component.sig/SMSIG/src/test/js_unit/AppCoreController.Test.js:1
Runner Started.
MainController : should check if all parameters are empty , ags_sig_app.Views.Main : Graph.checkParameters() ...
Failed.
MainController : should check that the GraphID exist for Display Mode, ags_sig_app.Views.Main : Graph.checkParameters() ...
Failed.
MainController : should check that the Context Parameters exist for SMUD Graph Providers, ags_sig_app.Views.Main : Graph.checkParameters() ...
Failed.
MainController : should check that the GraphMode exist, ags_sig_app.Views.Main : Graph.checkParameters() ...
Failed.
MainController : should check that Display scenario is ok, ags_sig_app.Views.Main : Graph.checkParameters() ...
Failed.
BUT, when i deploy my application in Jenkins the test case are not detected by Jenkins
the exec-maven-plugin does not run on jenkins.
[INFO] --- maven-compiler-plugin:3.0:compile (default-compile) # SMGC ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # SMGC ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory d:\.jenkins\jobs\com.sap.solman.graphical.component.sig.git\workspace\gitRepo\SMSIG\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.0:testCompile (default-testCompile) # SMGC ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # SMGC ---
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.676s
[INFO] Finished at: Thu Feb 20 17:23:29 CET 2014
[INFO] Final Memory: 13M/491M
[INFO] ------------------------------------------------------------------------
Finished: SUCCESS
This is the plugin my pom.xml:
<plugins>
<!-- Run jasmine unit tests with phantomjs ************************* -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>PhantomJS Unit Testing</id>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${basedir}/src/test/phantomjs_framework/phantomjs.exe</executable>
<arguments>
<argument>run_jasmine.js</argument>
<argument>test_runner.html</argument>
<!-- <argument>${project.build.directory}/surefire-reports</argument> -->
</arguments>
<workingDirectory>${basedir}/src/test/phantomjs_framework</workingDirectory>
</configuration>
</plugin>
Any ideas?
Kais.

Maven Findbugs not producing reports in site lifecycle

I'm trying to create the Findbugs HTML report for the site reports. I finally got Findbugs to actually run (before it would skip) because I had to include the goal findbugs in the <build> phase under the find bugs report. However, the findbugs.html report is not being generated even though I have findbugs defined in my <reporting> section.
Here's my configuration for Findbugs:
<build>
<plugins>
...
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<xmlOutput>true</xmlOutput>
</configuration>
<executions>
<execution>
<goals>
<goal>findbugs</goal>
</goals>
</execution>
</executions>
</plugin>
....
<plugins>
</build>
....
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.5.2</version>
<configuration>
<xmlOutput>true</xmlOutput>
<failOnError>false</failOnError>
<xmlOutput>true</xmlOutput>
<skip>false</skip>
</configuration>
</plugin>
</plugins>
<reporting>
My execution looks like this:
$ mvn clean site
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building project 2.0.4
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # crypto ---
[INFO] Deleting target
[INFO]
[INFO] --- maven-site-plugin:3.3:site (default-site) # crypto ---
[INFO] configuring report plugin org.apache.maven.plugins:maven-project-info-reports-plugin:2.7
[INFO] configuring report plugin org.codehaus.mojo:findbugs-maven-plugin:2.5.2
[INFO] configuring report plugin org.apache.maven.plugins:maven-pmd-plugin:3.0.1
[INFO] configuring report plugin org.apache.maven.plugins:maven-javadoc-plugin:2.9.1
[INFO]
[INFO] >>> maven-javadoc-plugin:2.9.1:aggregate (report:aggregate) # crypto >>>
[INFO]
[INFO] --- axis2-wsdl2code-maven-plugin:1.5.6:wsdl2code (default) # crypto ---
Retrieving document at 'src/main/wsdl/Tokenizer.wsdl'.
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # crypto ---
[INFO] Source directory: target/generated-sources added.
[INFO]
[INFO] <<< maven-javadoc-plugin:2.9.1:aggregate (report:aggregate) # crypto <<<
[INFO]
[INFO] >>> maven-javadoc-plugin:2.9.1:test-aggregate (report:test-aggregate) # crypto >>>
[INFO]
[INFO] --- axis2-wsdl2code-maven-plugin:1.5.6:wsdl2code (default) # crypto ---
Retrieving document at 'src/main/wsdl/SafeNetTokenizer.wsdl'.
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # crypto ---
[INFO] Source directory: /Users/david/workspace/KeyManagment-trunk/target/generated-sources added.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # crypto ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/david/workspace/KeyManagment-trunk/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # crypto ---
[INFO] Compiling 13 source files to /Users/david/workspace/KeyManagment-trunk/target/classes
[INFO]
[INFO] --- findbugs-maven-plugin:2.5.2:findbugs (default) # crypto ---
[INFO] Fork Value is true
[java] The following classes needed for analysis were missing:
[java] com.ingrian.internal.ilc.IngrianLogger
[java] com.ingrian.security.nae.NAESession
[java] com.ingrian.internal.config.Config
[java] com.ingrian.security.nae.NAEKey
[java] com.ingrian.security.nae.HmacSHA256
[java] com.ingrian.internal.xml.XMLException
[java] com.ingrian.security.nae.NAEAESCipher
[java] com.ingrian.security.nae.IngrianProvider
[java] Warnings generated: 310
[java] Missing classes: 8
[INFO] Done FindBugs Analysis....
[INFO]
[INFO] --- maven-bundle-plugin:2.3.7:manifest (bundle-manifest) # crypto ---
[INFO]
[INFO] <<< maven-javadoc-plugin:2.9.1:test-aggregate (report:test-aggregate) # crypto <<<
[INFO]
[INFO] >>> maven-javadoc-plugin:2.9.1:javadoc (report:javadoc) # crypto >>>
[INFO]
[INFO] --- axis2-wsdl2code-maven-plugin:1.5.6:wsdl2code (default) # crypto ---
Retrieving document at 'src/main/wsdl/SafeNetTokenizer.wsdl'.
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # crypto ---
[INFO] Source directory: /Users/david/workspace/KeyManagment-trunk/target/generated-sources added.
[INFO]
[INFO] <<< maven-javadoc-plugin:2.9.1:javadoc (report:javadoc) # crypto <<<
[INFO]
[INFO] >>> maven-javadoc-plugin:2.9.1:test-javadoc (report:test-javadoc) # crypto >>>
[INFO]
[INFO] --- axis2-wsdl2code-maven-plugin:1.5.6:wsdl2code (default) # crypto ---
Retrieving document at 'src/main/wsdl/SafeNetTokenizer.wsdl'.
[INFO]
[INFO] --- build-helper-maven-plugin:1.8:add-source (add-source) # crypto ---
[INFO] Source directory: /Users/david/workspace/KeyManagment-trunk/target/generated-sources added.
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # crypto ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/david/workspace/KeyManagment-trunk/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # crypto ---
[INFO] Compiling 2 source files to /Users/david/workspace/KeyManagment-trunk/target/classes
[INFO]
[INFO] --- findbugs-maven-plugin:2.5.2:findbugs (default) # crypto ---
[INFO] Fork Value is true
[java] The following classes needed for analysis were missing:
[java] com.ingrian.internal.ilc.IngrianLogger
[java] com.ingrian.security.nae.NAESession
[java] com.ingrian.internal.config.Config
[java] com.ingrian.security.nae.NAEKey
[java] com.ingrian.security.nae.HmacSHA256
[java] com.ingrian.internal.xml.XMLException
[java] com.ingrian.security.nae.NAEAESCipher
[java] com.ingrian.security.nae.IngrianProvider
[java] Warnings generated: 310
[java] Missing classes: 8
[INFO] Done FindBugs Analysis....
[INFO]
[INFO] --- maven-bundle-plugin:2.3.7:manifest (bundle-manifest) # crypto ---
[INFO]
[INFO] <<< maven-javadoc-plugin:2.9.1:test-javadoc (report:test-javadoc) # crypto <<<
[WARNING] No project URL defined - decoration links will not be relativized!
[INFO] Rendering site with org.apache.maven.skins:maven-default-skin:jar:1.0 skin.
[INFO] Skipped "JavaDocs" report, file "apidocs/index.html" already exists for the English version.
[INFO] Skipped "Test JavaDocs" report, file "testapidocs/index.html" already exists for the English version.
[INFO] Generating "About" report --- maven-project-info-reports-plugin:2.7
[INFO] Generating "Plugin Management" report --- maven-project-info-reports-plugin:2.7
...
[INFO] Generating "Project Team" report --- maven-project-info-reports-plugin:2.7
[INFO] Generating "Project Summary" report --- maven-project-info-reports-plugin:2.7
[INFO] Generating "Dependencies" report --- maven-project-info-reports-plugin:2.7
[INFO] Generating "CPD Report" report --- maven-pmd-plugin:3.0.1
[WARNING] Unable to locate Source XRef to link to - DISABLED
[INFO] Generating "PMD Report" report --- maven-pmd-plugin:3.0.1
[WARNING] Unable to locate Source XRef to link to - DISABLED
[INFO] Generating "JavaDocs" report --- maven-javadoc-plugin:2.9.1
[INFO]
Loading source files for package com.ihotelier.crypto...
Loading source files for package com.safenet.tokenization.wsclient...
Constructing Javadoc information...
Standard Doclet version 1.7.0_13
Building tree for all the packages and classes...
Generating ...
4 warnings
[WARNING] Javadoc Warnings
[WARNING] ...
[INFO] Fixed Javadoc frame injection vulnerability (CVE-2013-1571) in 1 files.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3:30.831s
[INFO] Finished at: Tue Nov 05 14:02:04 EST 2013
[INFO] Final Memory: 40M/115M
[INFO] ------------------------------------------------------------------------
I see findbugs being configured in the beginning of my execution under the maven-site-plugin. I see Findbugs executing (twice!) after maven-compiler-plugin runs. (I may change the goal to process-classes to prevent this double execution. I see 8 errors, but we don't really use those classes. (I need to figure out how to skip over these classes).
Near the end of the build, I see the PMD and CPD Reports being generated (Generating "CPD Report" report), but not Findbugs.
When I look at the build results, I see target/findbugs.xml and target/findbugsXML.xml, but nothing under target/site.
Sorry for the excessive output. I want to make sure I wasn't skipping anything important.
Shows you what I know about Maven. Two things I discovered:
Running site does not execute package (although compile does run -- probably because it's needed for some of the reports).
Findbugs cannot produce a site report unless the package is done first.
I moved findbugs plugin to run in the package phase, so it doesn't run twice, and everything now seems fine.
I think it's similar to the surefire reports issues, so try adding the site plugin to the <pluginManagement> section:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
</plugins>
</pluginManagement>

Resources