Archive

Archive for the ‘Build-Management’ Category

How to execute several maven plugins within a single build phase and set the respective execution order

You can use the build lifecycle or phases to control the order of the plugin execution. In some scenario, you have to bound few plugins to same phase, but still want to control the order of the plugin execution.

Plugins bound to the same build phase should be executed in the same order as they are listed in the POM. But under certain circumstances , the order is not executed in the expected order, see this MNG-2258 and MNG-3719. This bug is fixed in Maven 3.0.3. With Maven 3.0.3 and above plugins bound to same phase will be executed in the same order as they are listed in the pom.xml.

 

If you have to use an older Maven version you can spread the tasks to different phases. But I dont think there is much sence for this solution. You can also do one of the following to solve the problem:

  1. try your luck and see if Maven chosses the right order for you (you probably tried that already)
  2. use standalone plugin – run the goal outside the lifecycle. something like: mvn package org.codehaus.mojo:nsis-maven-plugin:1.0:compile.
  3. separate them into module: have a parent pom containing two sub modules, one – your war project and the other for the nsis project.
  4. use a custom lifecycle by changing the type, in your case you can use “exe”. this is done by using a custom plugin extension (guide to using extension)
  5. use the jetspeed-mvn-maven-plugin. I have never used it but it seems relevant to your needs.

 

Advertisements

Howto build single module from multimodule maven project

For building a single module one can use the reactor parameter ‘–projects’.

Example:

[root-directory]
- pom.xml (super POM)
- submodule1
  - src
  - pom.xml (sub POM)
- projects
  - doc
  - submodule2
    - src
    - pom.xml (sub POM)
mvn package --projects submodule1,projects\submodule2

Maven project descriptor

Reference
Maven 1.1 XSD
Maven 2.0 XSD

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion/>

  <parent>
    <groupId/>
    <artifactId/>
    <version/>
    <relativePath/>
  </parent>

  <groupId/>
  <artifactId/>
  <version/>
  <packaging/>

  <name/>
  <description/>
  <url/>
  <inceptionYear/>
  <organization>
    <name/>
    <url/>
  </organization>
  <licenses>
    <license>
      <name/>
      <url/>
      <distribution/>
      <comments/>
    </license>
  </licenses>

  <developers>
    <developer>
      <id/>
      <name/>
      <email/>
      <url/>
      <organization/>
      <organizationUrl/>
      <roles/>
      <timezone/>
      <properties>
        <key>value</key>
      <properties/>
    </developer>
  </developers>
  <contributors>
    <contributor>
      <name/>
      <email/>
      <url/>
      <organization/>
      <organizationUrl/>
      <roles/>
      <timezone/>
      <properties>
        <key>value</key>
      <properties/>
    </contributor>
  </contributors>

  <mailingLists>
    <mailingList>
      <name/>
      <subscribe/>
      <unsubscribe/>
      <post/>
      <archive/>
      <otherArchives/>
    </mailingList>
  </mailingLists>

  <prerequisites>
    <maven/>
  </prerequisites>

  <modules/>

  <scm>
    <connection/>
    <developerConnection/>
    <tag/>
    <url/>
  </scm>
  <issueManagement>
    <system/>
    <url/>
  </issueManagement>
  <ciManagement>
    <system/>
    <url/>
    <notifiers>
      <notifier>
        <type/>
        <sendOnError/>
        <sendOnFailure/>
        <sendOnSuccess/>
        <sendOnWarning/>
        <address/>
        <configuration>
          <key>value</key>
        <configuration/>
      </notifier>
    </notifiers>
  </ciManagement>

  <distributionManagement>
    <repository>
      <uniqueVersion/>
      <releases>
        <enabled/>
        <updatePolicy/>
        <checksumPolicy/>
      </releases>
      <snapshots>
        <enabled/>
        <updatePolicy/>
        <checksumPolicy/>
      </snapshots>
      <id/>
      <name/>
      <url/>
      <layout/>
    </repository>
    <snapshotRepository>
      <uniqueVersion/>
      <releases>
        <enabled/>
        <updatePolicy/>
        <checksumPolicy/>
      </releases>
      <snapshots>
        <enabled/>
        <updatePolicy/>
        <checksumPolicy/>
      </snapshots>
      <id/>
      <name/>
      <url/>
      <layout/>
    </snapshotRepository>
    <site>
      <id/>
      <name/>
      <url/>
    </site>
    <downloadUrl/>
    <relocation>
      <groupId/>
      <artifactId/>
      <version/>
      <message/>
    </relocation>
    <status/>
  </distributionManagement>

  <properties>
    <key>value</key>
  <properties/>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId/>
        <artifactId/>
        <version/>
        <type/>
        <classifier/>
        <scope/>
        <systemPath/>
        <exclusions>
          <exclusion>
            <artifactId/>
            <groupId/>
          </exclusion>
        </exclusions>
        <optional/>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId/>
      <artifactId/>
      <version/>
      <type/>
      <classifier/>
      <scope/>
      <systemPath/>
      <exclusions>
        <exclusion>
          <artifactId/>
          <groupId/>
        </exclusion>
      </exclusions>
      <optional/>
    </dependency>
  </dependencies>

  <repositories>
    <repository>
      <releases>
        <enabled/>
        <updatePolicy/>
        <checksumPolicy/>
      </releases>
      <snapshots>
        <enabled/>
        <updatePolicy/>
        <checksumPolicy/>
      </snapshots>
      <id/>
      <name/>
      <url/>
      <layout/>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <enabled/>
        <updatePolicy/>
        <checksumPolicy/>
      </releases>
      <snapshots>
        <enabled/>
        <updatePolicy/>
        <checksumPolicy/>
      </snapshots>
      <id/>
      <name/>
      <url/>
      <layout/>
    </pluginRepository>
  </pluginRepositories>

  <build>
    <sourceDirectory/>
    <scriptSourceDirectory/>
    <testSourceDirectory/>
    <outputDirectory/>
    <testOutputDirectory/>
    <extensions>
      <extension>
        <groupId/>
        <artifactId/>
        <version/>
      </extension>
    </extensions>
    <defaultGoal/>
    <resources>
      <resource>
        <targetPath/>
        <filtering/>
        <directory/>
        <includes/>
        <excludes/>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <targetPath/>
        <filtering/>
        <directory/>
        <includes/>
        <excludes/>
      </testResource>
    </testResources>
    <directory/>
    <finalName/>
    <filters/>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId/>
          <artifactId/>
          <version/>
          <extensions/>
          <executions>
            <execution>
              <id/>
              <phase/>
              <goals/>
              <inherited/>
              <configuration/>
            </execution>
          </executions>
          <dependencies>
            <dependency>
              <groupId/>
              <artifactId/>
              <version/>
              <type/>
              <classifier/>
              <scope/>
              <systemPath/>
              <exclusions>
                <exclusion>
                  <artifactId/>
                  <groupId/>
                </exclusion>
              </exclusions>
              <optional/>
            </dependency>
          </dependencies>
          <goals/>
          <inherited/>
          <configuration/>
        </plugin>
      </plugins>
    </pluginManagement>
    <plugins>
      <plugin>
        <groupId/>
        <artifactId/>
        <version/>
        <extensions/>
        <executions>
          <execution>
            <id/>
            <phase/>
            <goals/>
            <inherited/>
            <configuration/>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId/>
            <artifactId/>
            <version/>
            <type/>
            <classifier/>
            <scope/>
            <systemPath/>
            <exclusions>
              <exclusion>
                <artifactId/>
                <groupId/>
              </exclusion>
            </exclusions>
            <optional/>
          </dependency>
        </dependencies>
        <goals/>
        <inherited/>
        <configuration/>
      </plugin>
    </plugins>
  </build>

  <reports/>
  <reporting>
    <excludeDefaults/>
    <outputDirectory/>
    <plugins>
      <plugin>
        <groupId/>
        <artifactId/>
        <version/>
        <reportSets>
          <reportSet>
            <id/>
            <reports/>
            <inherited/>
            <configuration/>
          </reportSet>
        </reportSets>
        <inherited/>
        <configuration/>
      </plugin>
    </plugins>
  </reporting>

  <profiles>
    <profile>
      <id/>
      <activation>
        <activeByDefault/>
        <jdk/>
        <os>
          <name/>
          <family/>
          <arch/>
          <version/>
        </os>
        <property>
          <name/>
          <value/>
        </property>
        <file>
          <missing/>
          <exists/>
        </file>
      </activation>
      <build>
        <defaultGoal/>
        <resources>
          <resource>
            <targetPath/>
            <filtering/>
            <directory/>
            <includes/>
            <excludes/>
          </resource>
        </resources>
        <testResources>
          <testResource>
            <targetPath/>
            <filtering/>
            <directory/>
            <includes/>
            <excludes/>
          </testResource>
        </testResources>
        <directory/>
        <finalName/>
        <filters/>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId/>
              <artifactId/>
              <version/>
              <extensions/>
              <executions>
                <execution>
                  <id/>
                  <phase/>
                  <goals/>
                  <inherited/>
                  <configuration/>
                </execution>
              </executions>
              <dependencies>
                <dependency>
                  <groupId/>
                  <artifactId/>
                  <version/>
                  <type/>
                  <classifier/>
                  <scope/>
                  <systemPath/>
                  <exclusions>
                    <exclusion>
                      <artifactId/>
                      <groupId/>
                    </exclusion>
                  </exclusions>
                  <optional/>
                </dependency>
              </dependencies>
              <goals/>
              <inherited/>
              <configuration/>
            </plugin>
          </plugins>
        </pluginManagement>
        <plugins>
          <plugin>
            <groupId/>
            <artifactId/>
            <version/>
            <extensions/>
            <executions>
              <execution>
                <id/>
                <phase/>
                <goals/>
                <inherited/>
                <configuration/>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId/>
                <artifactId/>
                <version/>
                <type/>
                <classifier/>
                <scope/>
                <systemPath/>
                <exclusions>
                  <exclusion>
                    <artifactId/>
                    <groupId/>
                  </exclusion>
                </exclusions>
                <optional/>
              </dependency>
            </dependencies>
            <goals/>
            <inherited/>
            <configuration/>
          </plugin>
        </plugins>
      </build>

      <modules/>

      <distributionManagement>
        <repository>
          <uniqueVersion/>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </repository>
        <snapshotRepository>
          <uniqueVersion/>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </snapshotRepository>
        <site>
          <id/>
          <name/>
          <url/>
        </site>
        <downloadUrl/>
        <relocation>
          <groupId/>
          <artifactId/>
          <version/>
          <message/>
        </relocation>
        <status/>
      </distributionManagement>

      <properties>
        <key>value</key>
      <properties/>

      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId/>
            <artifactId/>
            <version/>
            <type/>
            <classifier/>
            <scope/>
            <systemPath/>
            <exclusions>
              <exclusion>
                <artifactId/>
                <groupId/>
              </exclusion>
            </exclusions>
            <optional/>
          </dependency>
        </dependencies>
      </dependencyManagement>
      <dependencies>
        <dependency>
          <groupId/>
          <artifactId/>
          <version/>
          <type/>
          <classifier/>
          <scope/>
          <systemPath/>
          <exclusions>
            <exclusion>
              <artifactId/>
              <groupId/>
            </exclusion>
          </exclusions>
          <optional/>
        </dependency>
      </dependencies>

      <repositories>
        <repository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <releases>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </releases>
          <snapshots>
            <enabled/>
            <updatePolicy/>
            <checksumPolicy/>
          </snapshots>
          <id/>
          <name/>
          <url/>
          <layout/>
        </pluginRepository>
      </pluginRepositories>

      <reports/>
      <reporting>
        <excludeDefaults/>
        <outputDirectory/>
        <plugins>
          <plugin>
            <groupId/>
            <artifactId/>
            <version/>
            <reportSets>
              <reportSet>
                <id/>
                <reports/>
                <inherited/>
                <configuration/>
              </reportSet>
            </reportSets>
            <inherited/>
            <configuration/>
          </plugin>
        </plugins>
      </reporting>
    </profile>
  </profiles>
</project>

How to find the goals of a Maven plugin

With the maven help plugin one can get informations about a particular maven plugin. The informations contain the available goals of the plugin.

mvn help:describe -Dplugin=<groupId>:<artifactId> -Ddetail

Example:

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-compiler-plugin -Ddetail

Maven warning message – “Selected war files include a WEB-INF/web.xml which will be ignored”

When I build my WAR package using Maven, I get this warning message:
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')

This warning is fixed in current version of maven-war-plugin:

<project>
    ...
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <webXml>src/main/webapp/WEB-INF/web.xml</webXml>
                </configuration>
            </plugin>
        </plugins>
    </build>
    ...
</project>

Maven Eclipse Compiler Error “No compiler is provided in this environment. …”

I got the following compilation error while running the Maven install command from Eclipse:

“No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?”

Go into Window > Preferences > Java > Installed JREs > and check your installed JREs. You should have an entry with a JDK there.

2013-03-08 10_37_19-Preferences

Go into Window > Preferences > Java > Installed JREs > Execution Environments

Select JavaSE-1.6, click the jdk checkbox on the right. Then use “update project configuration” from the maven menu.
2013-03-08 10_55_36-Preferences

For more informations about Maven and Eclipse have a look at the book of Sanjay Shah
here.
Maven-for-Eclipse

Eclipse Error: “Enabling Maven Dependency Management” has encountered a problem

February 17, 2013 7 comments

The following error apears if one imports a project which was created with Maven (mvn eclipse:eclipse) and tries the “Configure” -> “Convert to Maven Project” function:
An internal error occurred during: “Enabling Maven Dependency Management”. Unsupported IClasspathEntry kind=4

To fix this error open the project with Eclipse, run the “mvn eclipse:clean” command and try the “Configure” -> “Convert to Maven Project” function again.

Categories: Build-Management, Eclipse