4

I have a multi-module maven project that I can't get to compile. I have a Nexus repository sitting on my local network, and it is working (IntelliJ Idea is able to resolve my dependencies which reside only in that repository), and I am building through Jetbrains TeamCity. I am fairly certain that TeamCity is working since several other build configurations I have set up still work (using the same settings.xml). I am a bit of a loss for what could be causing the issue. Here are my pom files:

Parent pom:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company.product.plugins</groupId>
    <artifactId>plugin-parent</artifactId>
    <version>1.2-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>product-wireless-plugin</module>
        <module>product-paging-plugin</module>
    </modules>

    <distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://192.168.2.192:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://192.168.2.192:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <pluginRepositories>
        <pluginRepository>
            <id>autoincrement-versions-maven-plugin</id>
            <name>autoincrement-versions-maven-plugin</name>
            <url>http://autoincrement-versions-maven-plugin.googlecode.com/svn/repo</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>autoincrement-versions-maven-plugin</artifactId>
                <version>2.0-SNAPSHOT</version>
                <executions>
                    <execution>
                        <id>update-pom-versions</id>
                        <goals>
                            <goal>increment</goal>
                            <goal>commit</goal>
                        </goals>
                        <phase>compile</phase>
                        <configuration>
                            <autoIncrementVersion>true</autoIncrementVersion>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

product-wireless pom:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>plugin-parent</artifactId>
        <groupId>com.company.product.plugins</groupId>
        <version>1.2-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company.product.plugins</groupId>
    <artifactId>product-wireless-plugin</artifactId>
    <version>0.1.2</version>

    <distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://192.168.2.192:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://192.168.2.192:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <dependencies>
        <dependency>
            <groupId>com.company.product</groupId>
            <artifactId>product-common</artifactId>
            <version>0.9.1</version>
        </dependency>
    </dependencies>

</project>

product-paging pom:

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>plugin-parent</artifactId>
        <groupId>com.company.product.plugins</groupId>
        <version>1.2-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company.product.plugins</groupId>
    <artifactId>product-paging-plugin</artifactId>
    <version>0.1.2</version>

    <distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://192.168.2.192:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://192.168.2.192:8081/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
    </distributionManagement>

    <dependencies>
        <dependency>
            <groupId>com.company.product</groupId>
            <artifactId>product-common</artifactId>
            <version>0.9.1</version>
        </dependency>
    </dependencies>

</project>

And the error I am getting is:

com.company.product.plugins:product-wireless-plugin [13:54:16][com.company.product.plugins:product-wireless-plugin] Importing data from 'C:/TeamCity/buildAgent/work/40ac813105cf8bd7/product-wireless-plugin/target/surefire-reports/TEST-*.xml' with 'surefire' processor [13:54:16][com.company.product.plugins:product-wireless-plugin] Surefire report watcher [13:54:16][com.company.product.plugins:product-wireless-plugin] Downloading: repolocation/nexus/content/groups/public/com/company/product/product-parent/0.9.0/product-parent-0.9.0.pom [13:54:16][com.company.product.plugins:product-wireless-plugin] Failed to execute goal on project product-wireless-plugin: Could not resolve dependencies for project com.company.product.plugins:product-wireless-plugin:jar:0.1.2: Failed to collect dependencies for [com.company.product:product-common:jar:0.9.1 (compile)]

I am at quite a loss while trying to debug this... does anyone have any suggestions?

3
  • 1) For this "could not resolve dependencies" error, there is almost always a more detailed error message and/or stacktrace earlier in the build log. 2) Re-run the build with the -X flag.
    – noahlz
    Jun 18, 2013 at 19:19
  • @noahlz If you could post your comment as an answer, I will accept it. I was able to find the problem using that debug method. Jun 19, 2013 at 12:54
  • Running mvn install at root level project before running/packaging individual sub-project helped me
    – gtiwari333
    Feb 8, 2021 at 23:40

3 Answers 3

8

There are several approaches / tools for troubleshooting this sort of problem.

  1. For this "could not resolve dependencies" error, there is almost always a more detailed error message and/or stacktrace earlier in the build log. Maven logs are actually extremely verbose, to the point of having to search for the "root" error message several screens up from the build failure.

  2. Re-run the build with the -X flag. Here is documentation of Maven command line switches

  3. Another option is to use mvn dependency:tree to inspect the full graph of transitive dependencies. mvn help:effective-pom is another useful tool that prints out the pom.xml after considering your settings.xml, any active profiles, etc. Likewise mvn help:active-profiles

4

There are many problems in your multi-module build. The most important one is that you define a dependency:

<dependencies>
    <dependency>
        <groupId>com.company.product</groupId>
        <artifactId>product-common</artifactId>
        <version>0.9.1</version>
    </dependency>
</dependencies>

which seemed either not be existing in a repository or you have not access to the repository which contains it or your download has failed based on whatever reason (can't guess!). Are you using a repository manager like Artifactory, Nexus, Archiva? If not i recommend to start using one.

Apart from that you are using different versions for parent and the module in wireless-module:

   <parent>
        <artifactId>plugin-parent</artifactId>
        <groupId>com.company.product.plugins</groupId>
        <version>1.2-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.company.product.plugins</groupId>
    <artifactId>product-wireless-plugin</artifactId>
    <version>0.1.2</version>

A multi module build should define the version only via the parent and not within the artifact which means the above should look like this:

<modelVersion>4.0.0</modelVersion>
<parent>
    <artifactId>plugin-parent</artifactId>
    <groupId>com.company.product.plugins</groupId>
    <version>1.2-SNAPSHOT</version>
</parent>

<groupId>com.company.product.plugins</groupId>
<artifactId>product-wireless-plugin</artifactId>

The module should not define a version itself, cause it will inherit it from the parent. Furthermore you can see that you have a module which defines a release version (1.2) whereas the parent defines a SNAPSHOT version. An application/modules which are under development should define a version which is a SNAPSHOT version which means a thing like 1.2-SNAPSHOTetc.

The same applies accordingly for the definition of the distributionManagement. This should be defined only once in the parent of the project.

BTW. If you have several project the best is to define a company parent which contains some default definitions like distributionManagement, pluginManagement, dependencyManagement etc.

2
  • I disagree with you about the versioning needing to be the same between the children and the parent, as that was in fact the cause of my problem. The library "product-common" has a parent pom. I have kept the major version numbers in sync between the parent pom and all child poms. However, I will occasionally need to publish an update to one of the child poms (minor version) to fix a bug, and incrementing the version of all child libraries of the parent wouldn't make any sense. Version numbers cascade. If I have a version number in a child pom, it overrides the version in the parent. Jun 19, 2013 at 13:00
  • Also, the downvote was for not properly reading the question since the question did mention my Nexus repository and the fact that the library was resolving through my repo. Jun 19, 2013 at 13:08
2

Ok, I have solved the problem thanks to input from @noahlz. After utilizing the -X flag to debug my build, I was finding that the parent pom of "product-common" (product-parent) could not be found. After browsing my Sonatype Nexus repository, I discovered that my build system was only publishing new versions of the parent pom when new modules were added to it. So, even though my parent pom was on version 0.9.0, the repository had the latest version as 0.6.1. I suppose the "product-common" library was compiling correctly because it had access to the parent pom (with the 0.9.0 version number) at compile time. Either way, changing the parent pom version in "product-common" to point to the most recent in the repository resolved my build issues with my plugins.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.