2010/10/26 Babak Farhang <[email protected]>:
> Hi everyone,
>
> I have a nested, multi-module project in which every module's pom
> inherits from a root pom. I'd like to find a way to avoid duplicating
> the parent pom version number in every submodule. The aim is to keep
> the version number for these submodules in sync with one another, from
> one release to the next. Here's a strategy I've tried using
> profiles.xml that doesn't quite work.
>
> profiles.xml:
> ==========
>
> <profilesXml>
> <profiles>
> <profile>
> <id>projectProfile</id>
> <activation>
> <activeByDefault>true</activeByDefault>
> </activation>
> <properties>
> <!-- This is the property injection I'm having trouble with: -->
> <rootVersion>1.0.2</rootVersion>
> </properties>
> </profile>
> </profiles>
> </profilesXml>
>
>
> pom.xml (root):
> ============
>
> <?xml version="1.0" encoding="UTF-8"?>
> <project 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>com.myorg</groupId>
> <artifactId>root</artifactId>
> <name>Root</name>
> <version>${rootVersion}</version>
> <packaging>pom</packaging>
> <modules>
> <module>util</module>
> </modules>
> <properties>
> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> <org.springframework.version>3.0.2.RELEASE</org.springframework.version>
> <servlet.api.version>2.5</servlet.api.version>
> <log4j.version>1.2.16</log4j.version>
> <junit.version>3.8.1</junit.version>
> <httpclient.version>3.1</httpclient.version>
> <dnsjava.version>2.0.6</dnsjava.version>
> </properties>
>
> <build>
> <plugins>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-compiler-plugin</artifactId>
> <configuration>
> <source>1.6</source>
> <target>1.6</target>
> <encoding>UTF-8</encoding>
> <debug>true</debug>
> <showDeprecation>true</showDeprecation>
> <showWarnings>true</showWarnings>
> <compilerArgument>-Xlint</compilerArgument>
> <compilerArguments>
> <Xmaxerrs>10000000</Xmaxerrs>
> <Xmaxwarns>10000000</Xmaxwarns>
> </compilerArguments>
> <verbose/>
> </configuration>
> </plugin>
>
> <plugin>
> <groupId>org.apache.maven.plugins</groupId>
> <artifactId>maven-surefire-plugin</artifactId>
> <configuration>
> <forkMode>pertest</forkMode>
> <argLine>-Xms256m -Xmx1024m</argLine>
> <testFailureIgnore>false</testFailureIgnore>
> <skip>false</skip>
> <includes>
> <include>**/*Test.java</include>
> </includes>
> </configuration>
> </plugin>
> </plugins>
> </build>
> </project>
>
>
> util/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>
> <parent>
> <artifactId>root</artifactId>
> <groupId>com.myorg</groupId>
> <version>${rootVersion}</version>
> </parent>
>
> <artifactId>util</artifactId>
> <name>Common Utilities</name>
> <packaging>jar</packaging>
> <dependencies>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>${junit.version}</version>
> <scope>test</scope>
> </dependency>
>
> <dependency>
> <groupId>log4j</groupId>
> <artifactId>log4j</artifactId>
> <version>${log4j.version}</version>
> </dependency>
>
> </dependencies>
> </project>
>
>
> ================================
>
> On mvn install'ing from the root directory of the project here's the
> directory I get:
>
> % tree ~/.m2/repository/com/myorg
> myorg/
> |-- root
> | |-- 1.0.2
> | | `-- root-1.0.2.pom
> | `-- maven-metadata-local.xml
> `-- util
> |-- ${rootVersion}
> | |-- util-${rootVersion}.jar
> | `-- util-${rootVersion}.pom
> `-- maven-metadata-local.xml
>
> Note that ${rootVersion} was not transformed to 1.0.2. Also, here's
> what's inside the root pom file after it's been installed:
>
> % cat ~/m2/repository/com/myorg/root/1.0.2/root-1.0.2.pom
> <?xml version="1.0" encoding="UTF-8"?>
> <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocatio
> n="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd">
> <modelVersion>4.0.0</modelVersion>
> <groupId>com.myorg</groupId>
> <artifactId>root</artifactId>
> <name>Root</name>
> <version>${rootVersion}</version> <!-- why wasn't 1.0.2 injected here? -->
> <packaging>pom</packaging>
> <modules>
> <module>util</module>
> </modules>
> ..
>
> And here's the directory structrure I was hoping to get:
>
> myorg/
> |-- root
> | |-- 1.0.2
> | | `-- root-1.0.2.pom
> | `-- maven-metadata-local.xml
> `-- util
> |-- 1.0.2
> | |-- util-1.0.2.jar
> | `-- util-1.0.2.pom
> `-- maven-metadata-local.xml
>
>
>
>
>
> Any insights as to how I should approach this?
How Maven can evaluate ${rootVersion}? It needs ${rootVersion} to load
parent pom and then find ${rootVersion}
So for parent version you cannot used property.
What you can do is: set root version in parent definition like
<version>1.0</version>
And in pom version set it ${parent.version} like
<version>${parent.version}</version>
Then when update root version, you only need to change parent version
of all your pom xpath: /project/parent/version
Regards,
Arnaud.
>
> -Babak
>
> PS This email is somewhat related to
> http://www.mail-archive.com/[email protected]/msg113594.html
> There, the concern is to avoid duplicating version numbers for
> dependent artifacts: here the concern is to avoid duplicating the
> version number of the parent POM.
> Started this new thread in order to disambiguate these 2 related but
> still separate issues.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]