What is difference between <scope> and <phase> in maven plugin (jbehave example) - maven

As in title - here is piece of code.
I can have < scope > as well as < phase >
Jbehave documentation doesn't say much about it (http://jbehave.org/reference/stable/maven-goals.html)
<execution>
<id>run-stories</id>
<phase>test</phase>
<configuration>
<!--<scope>test</scope>-->
<includes>
<include>**/*Stories*.java</include>
</includes>
</configuration>
<goals>
<goal>run-stories-as-embeddables</goal>
</goals>
</execution>

The <phase/> element/property is a "standard" Maven property that indicates which phase of the Maven lifecycle the execution will occur in.
The <scope/> element/property you're referring to is specific to the JBehave plugin itself. Per the plugin's documentation, it seems that <scope/> is used to control which "set" of your project's Maven dependencies will be included in the JBehave plugin run. Per this answer on the JBehave site, it seems that, typically, JBehave is executed using only the project's main dependencies and code, not the test dependencies and code.

Related

${session.executionRootDirectory} is not recognized by sonar-maven-plugin

I have several levels of nested Maven projects, where every module can participate in the global integration tests. To have a global, multi module coverage, I've configured jacoco to use and share the same file accross modules, using the Maven variable ${session.executionRootDirectory}:
<execution>
<id>pre-integration-test</id>
<phase>pre-integration-test</phase>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<propertyName>jacoco.failsafeArgLine</propertyName>
<destFile>${session.executionRootDirectory}/target/jacoco-it.exec</destFile>
</configuration>
</execution>
This way, the same data file is used by each module, no matter how deep it is nested in the submodules. I've checked, a correct data file is generated by jacoco when launching "mvn clean install".
Now the problem appears when launching mvn sonar:sonar. It seems that the plugin can not replace that variable with the real path. I can see the following in the logs
[INFO] JaCoCoItSensor: JaCoCo IT report not found: /home/tomcat/.jenkins/jobs/MYJOB/workspace/${session.executionRootDirectory}/target/jacoco-it.exec
It doesn't work better when using #{session.executionRootDirectory}.
Any workaround?
Following a comment in this bug report at SonarSource, advising to use the following configuration:
<plugin>
<groupId>com.github.goldin</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>0.2.5</version>
<executions>
<execution>
<id>set-sonar.jacoco.reportPath</id>
<goals>
<goal>set-properties</goal>
</goals>
<phase>initialize</phase>
<configuration>
<rawProperties>
sonar.jacoco.itReportPath = ${session.executionRootDirectory}/target/jacoco-it.exec
</rawProperties>
<addDollar>true</addDollar>
</configuration>
</execution>
</executions>
</plugin>
... which was unfortunately not compatible with Maven 3.1+, I've used and built from sources that fork, and then I was able to make everything work correctly with Maven 3.2.3.

How do plugin goals tie into build phases in maven

How do plugins add to build phases.
I realize that maven has a list of goals that it executes by default but when we add a plugin node to the
pom.xml,
For example, as per the maven documentation if we include the following plugin
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<configuration>
<models>
<model>src/main/mdo/maven.mdo</model>
</models>
<version>4.0.0</version>
</configuration>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
</plugin>
Q1. What build phase does it tie into by default ?
Q2. Does it get executed in addition to the 'default' goal?, for example if i have a plugin that just echos 'hello'
and it gets tied to the compile phase, do i get a echo of 'hello' in addition to the compilation?
Thanks
Venu
You can see that in the documentation of the plugin which says the java goal is bound to generate-sources.
What you are talking about default goal does not exist. It makes more sense in the meaning of a default binding between maven-plugin:goal and the life-cycle phase in relationship with the packaging type of a project. There you have a kind of default binding which is defined in the Maven super pom which defines the goals and their execution in the life-cyclce.

What is meant by plugin goal in Maven speak?

I am a newbie to Maven . I am reading up Maven - The complete reference and came across the term Plugin Goals under the Build settings category of a pom.xml file :
In this section, we customize the behavior of the default Maven build.
We can change the location of source and tests, we can add new
plugins, we can attach plugin goals to the lifecycle, and we can
customize the site generation parameters.
Can you please explain with an example what is meant by attaching plugin goal to the lifecycle?
A plugin goal is a thing that a plugin does. Attaching a plugin goal to the lifecycle is saying to maven: when you are going through the lifecycle and are in this phase, trigger this plugin to do whatever the plugin does. This might sound rather confusing, so let's go through an example:
I want to deploy my application to the server each time I call mvn install. For this, in the build section of the pom , I add the following configuration:
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>7.1.1.Final</version>
<configuration>
...
</configuration>
<executions>
<execution>
<id>deploy-jar</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Take a look at the execution part: this describes how to attach the deploy goal of the jboss-as-maven-plugin to the install phase of the build lifecycle.
For further explanation of the maven lifecycle and it's phases, read this

Plugin execution not covered by lifecycle configuration: org.datanucleus:maven-datanucleus-plugin:3.0.1:enhance (execution: default, phase: compile)

I m using eclipse Juno
Version: Juno Release
Build id: 20120614-1722
POM.xml shows error as:
Plugin execution not covered by lifecycle configuration: org.datanucleus:maven-
datanucleus-plugin:3.0.1:enhance (execution: default, phase: compile)
<build>
<plugins>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>maven-datanucleus-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<fork>false</fork>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
<enhancerName>ASM</enhancerName>
<!-- <api>JPA</api> -->
<persistenceUnitName>applicatonPersistenceUnit</persistenceUnitName>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
Please advice... Thanks
You can get information about the background of this error from: http://wiki.eclipse.org/M2E_plugin_execution_not_covered
In summary, m2e execution inside eclipse might not work as expected for some phases, and maven requires an explicit command (i.e. ignore, execute or delegate) in order to decide what to do at that phase.
Recent eclipse versions (I am using Kepler) provide a "Quick fix" option when you right click on the error, and it adds the <pluginManagement> setting in your pom file. You can replace th <ignore /> action with the suitable one, if you prefer to "execute" or "delagate".
A similar problem was discussed here: How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds

Customize maven build

Is that possible to customize a maven build lifecycle without writing a plugin? I want to customize my project to package it without running tests, then run the tests. The background is that the tests are running on HTTPUnit and it needs a fully constructed web application directory structure.
As suggested by khmarbaise you can use maven-failsafe-plugin which is an extension of maven-surefire-plugin.
Maven lifecycle has four phases perfect for your intent:
pre-integration-test for setting up the integration test
environment.
integration-test for running the integration tests.
post-integration-test for tearing down the integration test
environment.
verify for checking the results of the integration
tests.
generally speaking during the pre-integration-test we start the server
eg:
<executions>
[...]
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run-exploded</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
I use this plugin with Hudson; in Maven Build Customization - Chapter 5 you can find further details.
It seems that you are writing integration tests.
You could use maven-failsafe-plugin. This plugin is executed by default at the integration-test phase of the maven build lifecycle (which is after the packaging phase)...
For those purposes you need the integration-test phase which exactly is intended for such things. It's after the packaging phase but before install/deploy phase.
This can be achieved by using the maven-failsafe-plugin. You can find a full example here.

Resources