Hello,
Because I think that is a quite useful enable access to dependency
properties inside pom, I am trying to develop a Maven plugin to set
properties in the following format:
${project.dependencies[groupId:artifactId].version|scope|type}
My mojo code is:
package com.provider.maven.plugins;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
/**
* @goal properties
* @requiresDependencyResolution
* @requiresProject
*/
public class EnableProjectPropertiesMojo extends AbstractMojo {
private static final String DEPENDENCY_PREFIX = "project.dependencies";
/**
* Instancia do projeto.
*
* @parameter default-value="${project}"
* @required
* @readonly
*/
private MavenProject project;
public void execute() throws MojoExecutionException {
for (Object object : project.getArtifacts()) {
Artifact artifact = (Artifact) object;
String artifactIdentification = DEPENDENCY_PREFIX + "["
+ artifact.getGroupId() + ":" + artifact.getArtifactId()
+ "].";
getLog().debug(
"Setting properties for '" + artifactIdentification +
"'");
String version = artifactIdentification + artifact.getVersion();
String scope = artifactIdentification + artifact.getScope();
String type = artifactIdentification + artifact.getType();
System.setProperty(version, artifact.getVersion());
System.setProperty(scope, artifact.getScope());
System.setProperty(type, artifact.getType());
}
}
}
And I have configure it in the build life cycle using:
<plugin>
<groupId>com.provider.maven.plugins</groupId>
<artifactId>maven-properties-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
But properties still not accessible in my pom. Some ideas what is wrong?
ps.: I've used ${project} instead of ${project.artifacts} because I plan to
extends this mojo later.
On 2/8/07, dawn.angelito <[EMAIL PROTECTED]> wrote:
Hi Marcos,
Instead of doing that, try this:
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${property.name}</version>
</dependency>
</dependencies>
<property.name>3.8.1</property.name>
Declare the version as a property then use that in your dependency.
Hope this helps.
Dawn
Marcos Silva Pereira wrote:
>
> How can I access dependency information inside the pom.xml? I would like
> to
> do something like the following:
>
> <property.name>${project.dependencies
[junit:junit].version}</property.name>
>
> In other words, how can I get the version from a dependency?
>
> Thanks...
>
> --
> Marcos Silva Pereira
> recife - pe
> [EMAIL PROTECTED]
> skype: marcos.silva.pereira
> http://blastemica.blogspot.com
>
>
--
View this message in context:
http://www.nabble.com/Access-dependency-properties-inside-pom.-tf3189482s177.html#a8860434
Sent from the Maven - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Marcos Silva Pereira
recife - pe
[EMAIL PROTECTED]
skype: marcos.silva.pereira
http://blastemica.blogspot.com