Hi everyone,

I'm trying to upgrade my project from Maven 2.2.1 to Maven 3.0.4 but am
running into problems with a dependency resolution. I spent a full day
trying to research this by looking through Maven documentation and similar
posts, but I'm still stuck. I posted on stackoverflow (
http://stackoverflow.com/q/10092772/1324379) but realized that this Maven
User List might be a better place to ask for help. Hope that's okay, and
thanks in advance for your help.

My project structure is as follows:

    pom.xml (acme-parent)
    child-alpha
    +-----> pom.xml

In addition, I have the following files in my own repository:


http://maven.my-own-repo.com/acme/child-dep-jdk15/maven-metadata-local.xml

http://maven.my-own-repo.com/acme/child-dep-jdk15/1.0/child-dep-jdk15-1.0.jar

http://maven.my-own-repo.com/acme/child-dep-jdk15/1.0/child-dep-jdk15-1.0.pom

child-alpha/pom.xml in turn has a profile dependency on my own
acme:child-dep-jdk15, which has been separately built into a jar file and
has its own .pom file specifying a parent that is the same acme-parent
parent as child-alpha.

Here are excerpts from the relevant files:

acme-parent pom.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>acme</groupId>
        <artifactId>acme-parent</artifactId>
        <name>Acme Parent Project</name>
        <version>1</version>
        <packaging>pom</packaging>

        <properties>...</properties>

        <modules>
            <module>child-alpha</module>
        </modules>

        <repositories>
            <repository>
                <id>acme-repo</id>
                <url>http://maven.my-own-repo.com</url>
            </repository>
            <repository>
                <id>central</id>
                <url>http://repo1.maven.org/maven2</url>
            </repository>
        </repositories>

        <pluginRepositories>...</pluginRepositories>

        <build>
          <plugins>...</plugins>
        </build>

        <dependencies>...</dependencies>
    </project>


child-alpha pom.xml:

    <project>
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>acme</groupId>
            <artifactId>acme-parent</artifactId>
            <version>1</version>
        </parent>
        <artifactId>child-alpha</artifactId>
        <name>Child Alpha Project</name>
        <version>1.0</version>
        <packaging>jar</packaging>

        <scm>...</scm>

        <properties>...</properties>

        <build>
          <resources>...</resources>
          <plugins>...</plugins>
        </build>

        <profiles>
            <profile>
                <id>jdk15</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                    <jdk>1.5</jdk>
                </activation>
                <dependencies>
                    <dependency>
                        <groupId>acme</groupId>
                        <artifactId>child-dep-jdk15</artifactId>
                        <version>1.0</version>
                    </dependency>
                </dependencies>
            </profile>
        </profiles>

        <dependencies>...</dependencies>
    </project>


child-dep-jdk15-1.0.pom:

    <project>
        <modelVersion>4.0.0</modelVersion>
        <parent>
            <groupId>acme</groupId>
            <artifactId>acme-parent</artifactId>
            <version>1</version>
        </parent>
        <groupId>acme</groupId>
        <artifactId>child-dep-jdk15</artifactId>
        <name>Acme Child Dependency</name>
        <version>1.0</version>
        <packaging>jar</packaging>

        <build>...</build>

        <dependencies>...</dependencies>
    </project>

When I tried to build child-alpha (while in the child-alpha directory), I
ran the following command:

    mvn -U -e clean install

And I got the following log messages and stack trace (extraneous messages
removed):

    Downloading:
http://maven2.my-own-repo.com/acme/acme-parent/1/acme-parent-1.pom
    Downloading:
http://repo1.maven.org/maven2/acme/acme-parent/1/acme-parent-1.pom

    [...]

    [ERROR] Failed to execute goal on project child-alpha: Could not
resolve dependencies for project acme:child-alpha:jar:1.0: [...]

    Caused by: org.apache.maven.project.DependencyResolutionException:
Could not resolve dependencies for project acme:child-alpha:jar:1.0: [...]

    Caused by:
org.sonatype.aether.collection.DependencyCollectionException: Failed to
collect dependencies for [...]
        at
org.sonatype.aether.impl.internal.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:258)
        at
org.sonatype.aether.impl.internal.DefaultRepositorySystem.collectDependencies(DefaultRepositorySystem.java:308)
        at
org.apache.maven.project.DefaultProjectDependenciesResolver.resolve(DefaultProjectDependenciesResolver.java:150)
        ... 23 more
    Caused by: org.sonatype.aether.resolution.ArtifactDescriptorException:
Failed to read artifact descriptor for acme:child-dep-jdk15:jar:1.0
        at
org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:331)
        at
org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:186)
        at
org.sonatype.aether.impl.internal.DefaultDependencyCollector.process(DefaultDependencyCollector.java:412)
        at
org.sonatype.aether.impl.internal.DefaultDependencyCollector.collectDependencies(DefaultDependencyCollector.java:240)
        ... 25 more
    Caused by:
org.apache.maven.model.resolution.UnresolvableModelException: Could not
find artifact acme:acme-parent:pom:1 in acme-repo (
http://maven.my-own-repo.com)
        at
org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:126)
        at
org.apache.maven.model.building.DefaultModelBuilder.readParentExternally(DefaultModelBuilder.java:813)
        at
org.apache.maven.model.building.DefaultModelBuilder.readParent(DefaultModelBuilder.java:664)
        at
org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:310)
        at
org.apache.maven.model.building.DefaultModelBuilder.build(DefaultModelBuilder.java:232)
        at
org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:322)
        ... 28 more
    Caused by: org.sonatype.aether.resolution.ArtifactResolutionException:
Could not find artifact acme:acme-parent:pom:1 in acme-repo (
http://maven.my-own-repo.com)
        at
org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:538)
        at
org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:216)
        at
org.sonatype.aether.impl.internal.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:193)
        at
org.apache.maven.repository.internal.DefaultModelResolver.resolveModel(DefaultModelResolver.java:122)
        ... 33 more
    Caused by: org.sonatype.aether.transfer.ArtifactNotFoundException:
Could not find artifact acme:acme-parent:pom:1 in acme-repo (
http://maven.my-own-repo.com)
        at
org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:947)
        at
org.sonatype.aether.connector.wagon.WagonRepositoryConnector$4.wrap(WagonRepositoryConnector.java:941)
        at
org.sonatype.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:669)
        at
org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:60)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:680)

While using Maven 2, I've never needed the acme-parent pom.xml at the
following location:
http://maven2.my-own-repo.com/acme/acme-parent/1/acme-parent-1.pom

The reason we don't have the parent pom.xml on our own repo is is that we
have a script used when creating version control branches that changes some
<properties></properties> values in acme-parent pom.xml depending on which
branch we're on, so it would be complicated to put that pom.xml in the repo
and keep it correctly updated for all the different branches we're trying
to build concurrently with our continuous integration server.

In Maven 2, when doing builds of child-alpha, Maven would have no trouble
finding acme-parent pom.xml one directory up, i.e. with a relative path of
../pom.xml, so it would never try going to my repositories to find it.
Having the parent pom.xml in my local checkout only and not having it in
the repo worked fine in Maven 2.

However, when I tried building child-alpha under Maven 3.0.4, the exception
above occurred. At first, I thought I needed to explicitly set the
relativePath within the <parent></parent> tags at the top of child-alpha's
pom.xml, but that didn't fix it -- and acme-parent's pom.xml is indeed
already in the default relativePath of ../pom.xml, so there's no need to
explicitly set it.

Then, I tried commenting out the child-dep-jdk15 dependency within the
<profiles></profiles> section of child-alpha's pom.xml. The child-alpha
maven build completes successfully with this dependency commented out.

I don't understand why child-alpha won't build in Maven 3 when the
child-dep-jdk15 dependency is in place. If Maven was able to correctly find
the acme-parent pom.xml initially (per the <parent></parent> block at the
top), why is it now trying to download it from the repos when processing
the child-dep-jdk15 dependency? Have I configured something incorrectly,
and if so, how should I fix it?

One other thing: if I first run `mvn -N install` in the same directory as
acme-parent's pom.xml, and then try building child-alpha, then the
child-alpha build succeeds, even when keeping the dependency
child-dep-jdk15 in the code. After I run that command, I'm able to verify
acme-parent-1.pom is in my local .m2 directory.  While this workaround may
be okay for individual developers, it'd be a problem for our continuous
integration server, which needs to be able to run concurrent builds for
different branches.

I'd strongly prefer not to have to reconfigure my repository to host the
acme-parent pom.xml due to the version control branching changes I've
mentioned above.

Reply via email to