Maven Multi-Module Project, Not Resolving Dependencies - maven

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?

There are several approaches / tools for troubleshooting this sort of problem.
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.
Re-run the build with the -X flag. Here is documentation of Maven command line switches
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

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.

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.

Related

Deploy Two Wars to a Repository with One Pom

I have a single project that builds two war files. The only difference between the two are configuration files and the war name. I'm trying to deploy the wars to our Nexus repository for distribution management. I know how to name the wars differently in the pom by using:
<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>
<artifactId>example</artifactId>
<version>1.1.2</version>
<packaging>war</packaging>
<properties>
<buildVersion>counter</buildVersion>
</properties>
<build>
<finalName>example_${buildVersion}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>nexus.example</id>
<url>https://example.com/nexus/content/repositories/wars</url>
</repository>
</distributionManagement></project>
But, when I run mvn deploy, the name of the war that is deployed doesn't have the buildVersion so both wars are named the same.
I've found the deploy:deploy-file directive, but it needs the version of the war that's being deployed defined as a -D spec. Since I'm doing CD, I don't have the version on the command line within Bamboo.
Has anyone come across this situation before and what was done to accomplish it?

how to avoid inheritance of <site> and <url> from Maven parent POM?

This question has no Maven multi module context
In my projects, I often use a parent POM which defines some Maven plugins.
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company</groupId>
<artifactId>commonParent</artifactId>
<version>1.2.2</version>
<packaging>pom</packaging>
<build>
<plugins>
</plugins>
</build>
<distributionManagement>
<repository> </repository>
<snapshotRepository> </snapshotRepository>
<site>
<id>releases</id>
<url>dav:http://intra.nexus.de/repository/company-docs/${artifactId}</url>
</site>
</distributionManagement>
</project>
I have a small documentation for this parent POM, which is deployed to Nexus 3 using the maven site plugin. Works fine.
I use this parent in other projects (packaging war and jar), which have a documentation, too. And they have their own <site> and <url> elements:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.company</groupId>
<artifactId>commonParent</artifactId>
<version>1.2.2</version>
</parent>
<artifactId>myProject</artifactId>
<version>2.0.0</version>
<packaging>war</packaging>
<distributionManagement>
<repository> </repository>
<snapshotRepository> </snapshotRepository>
<site>
<id>releases</id>
<url>dav:http://intra.nexus.de/repository/company-docs/${artifactId}</url>
</site>
</distributionManagement>
</project>
When I deploy the site with mvn site:deploy, I get this output:
Pushing D:\dev\myProject\target\site
to http://intra.nexus.de/repository/company-docs/commonParent../myProject`
How can I avoid the inheritance of <site> from the parent to my project?
From the documentation of Maven Site Plugin:
If subprojects inherit the site URL from a parent POM, they will automatically append their to form their effective deployment location.
But, as soon as the parent project is not the direct ancestor, Maven will generated inadequate url and site/url values.
E.g. with a parent project which is not the root project.

Apply a Variable or Profile to a Downloaded Parent Pom

I have a Pom.xml that downloads a Parent Pom for it's <distributionmanagement> from. I am trying to have where the project deploys to be dependent upon a variable within the Parent Pom. Below is my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dev</groupId>
<artifactId>company-parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<distributionManagement>
<repository>
<id>Artifactory</id>
<name>Artifactory-releases</name>
<url>http://artifactory:8081/artifactory/${repo}</url>
</repository>
<snapshotRepository>
<id>Artifactory</id>
<name>Artifactory-snapshots</name>
<url>http://artifactory:8081/artifactory/${repo}</url>
</snapshotRepository>
</distributionManagement>
</project>
When I run a mvn deploy I use the command line mvn deploy -Drepo=integration but it does not work. The deploy just places the project in dev and not integration like the variable says to. The parent pom is hosted on artifactory so I believe that because it is downloaded during the deploy the variable isn't being applied to it.

integration of sbt (play!) project with maven parent pom

I have a maven project with multiple maven modules organized around parent pom. All these modules are packaged into JAR files which are dependencies of my Play! application built as a SBT project:
MyProject
-> pom.xml (parent)
MavenModule1
-> pom.xml (child pom)
MavenModule2
-> pom.xml (child pom)
PlayApplication
-> Build.scala (SBT project)
Since all maven modules are child projects of parent module (MyProject), I can go to 'MyProject', execute mvn clean install and entire project, except PlayApplication will be built.
The question is how can I modify parent pom/SBT build file to fire PlayApplication build together with the rest of modules?
(I know that probably there is no simple, build-in way to do it, so all hacks are welcomed :))
Use play2-maven-plugin - you can compile project as normal maven project.
Example of Build.scala (all changes should be synchronized between pom and Build.scala)
import sbt._
import Keys._
import play.Project._
import Path._
object ApplicationBuild extends Build {
val myExternalPom = super.settings ++ externalPom(baseDirectory(_ / "pom.xml"))
val appName = "PlayApplication"
val appVersion = "1.0.0"
val appDependencies = Seq(
jdbc,
anorm
)
val main = play.Project(appName, appVersion, appDependencies,file(".")).settings(
resolvers ++= Seq( "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
, "central" at "http://artifactory:8081/artifactory/libs-release")
).settings(
externalPom() :_*
)
}
Pom file
<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>test</groupId>
<artifactId>test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>play2</packaging>
<name>Play! Framework 2.x Maven Test Project</name>
<repositories>
<repository>
<id>typesafe</id>
<name>Typesafe - releases</name>
<url>http://repo.typesafe.com/typesafe/releases/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<play2.plugin.version>1.0.0-alpha1</play2.plugin.version>
<play2.version>2.1.0</play2.version>
<play2-scala.version>2.10</play2-scala.version>
<scala.version>2.10.0</scala.version>
</properties>
<parent>
<groupId>com.company.project</groupId>
<artifactId>my-parent-pom</artifactId>
<version>1.0.0</version>
</parent>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>${scala.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>play</groupId>
<artifactId>play_${play2-scala.version}</artifactId>
<version>${play2.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${basedir}/app</sourceDirectory>
<resources>
<resource>
<directory>${basedir}/conf</directory>
</resource>
<resource>
<directory>${basedir}</directory>
<includes>
<include>public/**</include>
</includes>
</resource>
</resources>
<directory>${basedir}/target/scala-${play2-scala.version}</directory>
<plugins>
<plugin>
<groupId>com.google.code.play2-maven-plugin</groupId>
<artifactId>play2-maven-plugin</artifactId>
<version>1.0.0-alpha1</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
Move all dependencies from Build.scala to pom file. Maven do not know about Build.scala (I do not test it)
NOTE
If you use the eclipse IDE (scala-ide) - please run command:
play eclipse always when you update pom file. This command updates .classpath . In idea I think dependencies are update automatically.
UPDATE
Add <directory>${basedir}/target/scala-${play2-scala.version}</directory> to pom file. Play by default compile all to this directory (problem in idea).
FOR IDEA COMMUNITY VERSION
You can use idea without play plugin - import your project as maven project to idea. Do not call play idea before.

no any "plugin descriptor" founded in my maven project

I am wanting to create UI with qt-jambi, but i have a problem.
i am using maven in eclipse, and create a maven project, and i downloaded and installed 3rd party qt-jambi jar files in my local repository from here:
http://old.qt-jambi.org/maven2/net/sf/qtjambi/
and below files:
(1) qtjambi-maven-plugin-linux32-4.5.2_01.jar
(2) qtjambi-platform-linux32-4.5.2_01.jar
i am using ubuntu 12.10(32bit) and Maven 3.0.4.
My maven repository(m2 home)path for qt-jambi is like below:
/home/mehdi/.m2/repository/net/sf/qtjambi/qtjambi/4.5.2_01/qtjambi-4.5.2_01.jar
/home/mehdi/.m2/repository/net/sf/qtjambi/qtjambi-maven-plugin-linux32/4.5.2_01/qtjambi-maven-plugin-linux32-4.5.2_01.jar
so i add this lines to my pom.xml: http://old.qt-jambi.org/users/maven-repository/
my pom.xml file is:
<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.iyasin</groupId>
<artifactId>iycTest</artifactId>
<version>2.0</version>
<packaging>jar</packaging>
<name>iycTest</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>net.sf.qtjambi</groupId>
<artifactId>qtjambi</artifactId>
<version>4.5.2_01</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.sf.qtjambi</groupId>
<artifactId>qtjambi-maven-plugin-linux32</artifactId>
<executions>
<execution>
<id>qtjambi</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<sourcesDir>src/main/java</sourcesDir>
<noObsoleteTranslations>true</noObsoleteTranslations>
</configuration>
</plugin>
</plugins>
</build>
</project>
and when run mvn test or mvn compile return me below error:
Failed to parse plugin descriptor for net.sf.qtjambi:qtjambi-maven-plugin-linux32:4.5.2_01 (/home/mehdi/.m2/repository/net/sf/qtjambi/qtjambi-maven-plugin-linux32/4.5.2_01/qtjambi-maven-plugin-linux32-4.5.2_01.jar): No plugin descriptor found at META-INF/maven/plugin.xml -> [Help 1]
You need to add into the relevant part of your POM:
<pluginRepositories>
<pluginRepository>
<id>qtjambi-releases-before-2011</id>
<name>QtJambi (Releases Before 2011)</name>
<url>http://repository.qt-jambi.org/nexus/content/repositories/releases-before-2011</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
The above can be put into your settings.xml or project POM.
You should really run a local repository proxy (such as Nexus or Artifactory). Then setup your settings.xml to point to that local repository. Then configure it to cache central and qtjambi and other repositories you use. However that benefits of this are too long to go into here, best to research the topic with google.

Resources