Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aether-users] Correctly building dependencies from a POM

Hi,

I'm trying to add the ability to read a pom.xml file within a Grails application. So I have logic like this:

        if (readPom) {
            def pomFile = new File(basedir, "pom.xml")

            final modelRequest = new DefaultModelBuildingRequest()
            modelRequest.setPomFile(pomFile)
            ModelBuildingResult modelBuildingResult = modelBuilder.build(modelRequest)
            final mavenDependencies = modelBuildingResult.getRawModel().getDependencies()
            for (org.apache.maven.model.Dependency md in mavenDependencies) {
                final dependency = new Dependency(new DefaultArtifact(md.groupId, md.artifactId, md.classifier, md.type, md.version), md.scope)
                addDependency(dependency)
            }
        }

Which reads the POM and converters the Maven dependencies into Aether's model. The problem I'm running in to is that properties are not correctly evaluated. The pom.xml file defines a property like:


    <properties>
        <grails.version>2.3.0.BUILD-SNAPSHOT</grails.version>
    </properties>


Which is later used in the dependency definitions:


        <dependency>
            <groupId>org.grails</groupId>
            <artifactId>grails-dependencies</artifactId>
            <version>${grails.version}</version>
            <type>pom</type>
        </dependency>

This works fine when using the 'mvn' command but when using 'grails' and hence the code originally posted above. I get the following exception:

at java.net.URI$Parser.fail(URI.java:2810)
at java.net.URI$Parser.checkChars(URI.java:2983)


The properties don't appear to be being substituted.

Is there a correct way to convert the Maven model into the Aether model that deals with this issue?

Thanks again

--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

Back to the top