Re: Maven example
On 2009-06-03 14:07:11 -0400, Roedy Green
<see_website@mindprod.com.invalid> said:
On Wed, 3 Jun 2009 11:01:14 -0400, Owen Jacobson
<angrybaldguy@gmail.com> wrote, quoted or indirectly quoted someone
who said :
Feel free to pick over it and see if there's anything useful.
Thanks. The pom files don't seem to contain much low level
information. I gather they have a standard way of handling all the
low level details.
Indeed they do. The <packaging> element, near the top, is enough to
tell maven *how* to build things, in most cases:
<packaging>jar</packaging, for example, causes src/main/java to be
compiled, src/main/resources to be copied (and optionally filtered
through a token-replacement layer), src/test/java to be compiled and
run as test cases, then the resulting classes and files from src/main
used to build a JAR. There are built-in packaging types for JARs, WARs,
EARs, EJB-JARs, RARs and some maven infrastructure types like pom. New
packaging types (with associated "standard" build procedures) can be
implemented as plugins - there are, for example, plugins for JBoss SAR
files, Flex applications and libraries, and a bunch of other things.
If you need to specify things about *how* to build something, you can
add new plugins to the build (not shown in the example, but I can cook
one up) or reconfigure the standard plugins to behave differently.
There's also an inheritance model, where projects can inherit settings,
including
Most of the information in pom.xml is actually not related to building
the project at all: it's metadata about the project. I've annotated one
of my single-module POMs (below) to give a better idea of how to use it
in a simple project, and a better idea of what's optional versus
mandatory. A lot of the things in my own projects' POMs are required
for projects being uploaded to central (http://repo1.maven.org/maven2/)
but not for in-house projects -- license metadata, for example, is less
relevant if code isn't being released outside of an organization.
For a really simple JAR project with no dependencies, and that doesn't
need to meet anyone's metadata strictness requirements, this is a
complete POM:
--- minimal-pom.xml ---
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ca.grimoire.examples</groupId>
<artifactId>tiny-pom</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>A very short example POM</name>
</project>
--- EOF ---
See http://mindprod.com/jgloss/maven.html
A nice start. I'm happy to contribute, but I've learned I do a better
job of explaining things when people ask questions than when I just
ad-lib for an hour.
-o
--- Annotated pom.xml, adapted from
http://alchemy.grimoire.ca/hg/mainspring-daemon/file/2465413158e6/pom.xml
---
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- A reference to a POM to inherit settings from. (Optional, useful
in multiple-JAR projects or for inheriting organization-wide
defaults.)-->
<parent>
<artifactId>alchemy-parent</artifactId>
<groupId>ca.grimoire</groupId>
<version>4</version>
</parent>
<!-- The project identifier consists of a groupId, which may be shared
between projects, and an artifactId, which must be unique within
a groupId. -->
<groupId>ca.grimoire</groupId>
<artifactId>mainspring-daemon</artifactId>
<!-- The type of project being built. Maven uses this to decide how to
perform the build itself. -->
<packaging>jar</packaging>
<!-- The project's version. The suffix -SNAPSHOT marks this build as a
development build, not intended for use outside the project. -->
<version>1.0-SNAPSHOT</version>
<!-- Human-readable, decorative name for the project. -->
<name>Mainspring Uncontainer for Daemons</name>
<!-- The project's homepage. (Optional.) -->
<url>http://alchemy.grimoire.ca/m2/sites/ca.grimoire/mainspring-daemon</url>
<!-- A human-readable description of the project. (Optional.) -->
<description>
Mainspring provides a way to bootstrap Spring contexts from JARs
without a web or application container. This version uses
commons-daemon to bootstrap, rather than main().
</description>
<!-- A list of developers and contributors involved in the project.
(Optional.) -->
<developers>
<developer>
<id>owen.jacobson</id>
<name>Owen Jacobson</name>
<email>owen.jacobson@grimoire.ca</email>
<timezone>-5</timezone>
</developer>
</developers>
<!-- The license or licenses the project is being distributed under.
(Optional.) -->
<licenses>
<license>
<name>MIT</name>
<url>http://alchemy.grimoire.ca/licenses/MIT-LICENSE</url>
</license>
</licenses>
<!-- Version control information. (Optional, but recommended.) -->
<scm>
<!-- For users and third-party developers without commit access. -->
<connection>
scm:hg:http://alchemy.grimoire.ca/hg/mainspring-daemon/
</connection>
<!-- For developers with commit access. The developerConnection URL
is also used by certain plugins, including the 'release'
plugin, to track automated changes to the project. -->
<developerConnection>
scm:hg:http://alchemy.grimoire.ca/hg/mainspring-daemon/
</developerConnection>
</scm>
<!-- A link to the project's bug tracker. (Optional.) -->
<issueManagement>
<system>JIRA</system>
<url>http://alchemy.grimoire.ca/jira/browse/MS</url>
</issueManagement>
<!-- A link to the project's build server. (Optional.) -->
<ciManagement>
<system>Hudson</system>
<url>http://alchemy.grimoire.ca/hudson/</url>
</ciManagement>
<!-- The projects needed to build or run this project. (Semi-optional:
if your project has no dependencies, you can omit this.) -->
<dependencies>
<!-- A normal dependency, needed to build and run the project. -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>2.5.6</version>
</dependency>
<dependency>
<groupId>commons-daemon</groupId>
<artifactId>commons-daemon</artifactId>
<version>1.0.1</version>
</dependency>
<!-- A dependency that's only needed during testing. -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit-dep</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>2.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Controls reports that appear if you're using the maven website
generation tools. (Optional.) -->
<reporting>
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<configuration>
<links>
<link>http://java.sun.com/javase/6/docs/api</link>
<link>
http://static.springframework.org/spring/docs/2.5.x/api
</link>
</links>
</configuration>
</plugin>
</plugins>
</reporting>
<!-- URLs to upload various build products to. (Optional.) -->
<distributionManagement>
<!-- Where to upload "release" (non-SNAPSHOT) builds. -->
<repository>
<id>alchemy.grimoire.ca</id>
<url>dav:http://alchemy.grimoire.ca/m2/releases/</url>
</repository>
<!-- Where to upload "development" (SNAPSHOT) builds. -->
<snapshotRepository>
<uniqueVersion>false</uniqueVersion>
<id>alchemy.grimoire.ca</id>
<url>dav:http://alchemy.grimoire.ca/m2/snapshots/</url>
</snapshotRepository>
<!-- Where to upload the maven generated website. -->
<site>
<id>alchemy.grimoire.ca</id>
<url>dav:http://alchemy.grimoire.ca/m2/sites/ca.grimoire/mainspring-daemon</url>
</site>
</distributionManagement>
</project>
--- EOF ---