Maven project with multiple modules, not dependency resolution

I have a multi-module maven project that I cannot compile. I have a Nexus repository sitting on my local network and it works (IntelliJ Idea can resolve my dependencies that are only in this repository) and I create Jetbrains TeamCity. I'm pretty sure TeamCity has been working since the several other build configurations I installed still work (using the same settings.xml parameter). I will lose a little bit that may cause a problem. 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> 

paging paging product:

 <?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 get is:

com.company.product.plugins: product-wireless-plugin [13:54:16] [com.company.product.plugins: product-wireless-plugin] Import data from "C: / TeamCity / buildAgent / work / 40ac813105cf8bd7 / product-wireless-plugin / target / surefire-reports / TEST - *. xml 'with the processor' surefire '[13:54:16] [com.company.product.plugins: product-wireless-plugin] Surefire report watcher [13 : 54: 16] [com.company.product.plugins: product-wireless-plugin] Download: 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 complete the goal in the wireless plug-in project: failed to resolve dependencies for the com.company.product.plugins project : product- wireless-plugin: jar: 0.1.2: Failed to build the dependency and [com.company.product: product-common: jar: 0.9.1 (compilation)]

I am very happy trying to debug this ... does anyone have any suggestions?

+4
source share
3 answers

There are several approaches / tools to fix this problem.

  • For this error, “Unable to resolve dependencies”, a more detailed error message and / or stacktrace appears almost always in the build log earlier. Maven logs are actually extremely detailed, in terms of finding the “root” error message for multiple screens from assembly failure.

  • Re-run the assembly with the -X flag. Here is the documentation for Maven command line commands

  • Another option is to use mvn dependency:tree to check the full schedule of transitive dependencies. mvn help:effective-pom is another useful tool that displays pom.xml after reviewing your .xml settings, any active profiles, etc. Similar to mvn help:active-profiles

+7
source

Ok, I solved the problem thanks to input from @noahlz. After using the -X flag to debug my build, I found that the parent pom "product-common" (product-parent) could not be found. After looking at my Sonatype Nexus repository, I found that my build system only published new versions of the parent pump when new modules were added to it. So, although my parent pom was on version 0.9.0, the repository had the latest version as 0.6.1. I believe that the product-general library was compiled correctly, because at compile time it had access to the parent pom (version number 0.9.0). In any case, by changing the parent version of pom in the "common product" to indicate the latest in the repository, the problems with my build with my plugins were resolved.

+2
source

There are a lot of problems in your multi-module assembly. Most importantly, you define the dependency:

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

which, it seemed, either did not exist in the repository, or you do not have access to the repository that contains it, or the download did not work for any reason (I can’t guess!). Do you use a storage manager, for example, Artifactory, Nexus, Archiva? If not, I recommend starting using it.

In addition, you use different versions for the parent and module in the 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 assembly should determine the version only through the parent, and not inside the artifact, which means that 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 does not have to determine the version on its own, because it inherits it from the parent. In addition, you can see that you have a module that defines the release version (1.2), while the parent determines the version of SNAPSHOT. The developed application / modules should determine the version, which is the version of SNAPSHOT, which means such a thing as 1.2-SNAPSHOT , etc.

The same applies to the definition of distribution. This should be defined only once in the parent project object.

BTW. If you have several projects, it is best to identify the parent of the company, which contains some default definitions, such as distributionManagement, pluginManagement, dependencyManagement, etc.

0
source

Source: https://habr.com/ru/post/1486897/


All Articles