Unable to build specific child projects in Maven using mvn package or IntelliJ tool windows - maven

I have the following project structure in Maven:
./
├─ app1/
│ ├─ pom.xml
├─ app2/
│ ├─ pom.xml
├─ core/
│ ├─ pom.xml
├─ pom.xml
My parent pom.xml contains the following:
<packaging>pom</packaging>
<modules>
<module>core</module>
<module>app1</module>
<module>app2</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.9</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.acme</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
<repositories>
<repository>
<id>Maven central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>Confluent</id>
<url>https://packages.confluent.io/maven/</url>
</repository>
<repository>
<id>Local Maven</id>
<name>Local Maven Repository</name>
<url>file://${user.home}/.m2/repository/</url>
</repository>
</repositories>
My core pom.xml contains the following:
<parent>
<groupId>com.acme</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>core</artifactId>
<version>1.0.0-SNAPSHOT</version>
My app1 pom.xml contains the following:
<parent>
<groupId>com.acme</groupId>
<artifactId>parent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>app1</artifactId>
<dependencies>
<dependency>
<groupId>com.acme</groupId>
<artifactId>core</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- ... -->
</dependencies>
If I try to build in the root project directory, via:
mvn package
it correctly builds all my modules.
If I try to build the core package (which does not have additional intra-project dependencies) via mvn package, it correctly builds.
But if I try to build the app1 package (which does contain a dependency on my core module), even while forcing updates:
user#dev:~/parent/app1$ mvn package -U
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.acme:app1 >----------------
[INFO] Building app1 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
Downloading from Local Maven: file:///home/user/.m2/repository/com/acme/core/1.0.0-SNAPSHOT/maven-metadata.xml
Downloading from Maven central: https://repo1.maven.org/maven2/com/acme/core/1.0.0-SNAPSHOT/maven-metadata.xml
Downloading from Confluent: https://packages.confluent.io/maven/com/acme/core/1.0.0-SNAPSHOT/maven-metadata.xml
Downloading from Confluent: https://packages.confluent.io/maven/com/acme/parent/1.0.0-SNAPSHOT/maven-metadata.xml
Downloading from Maven central: https://repo1.maven.org/maven2/com/acme/parent/1.0.0-SNAPSHOT/maven-metadata.xml
Downloading from Local Maven: file:///home/user/.m2/repository/com/acme/parent/1.0.0-SNAPSHOT/maven-metadata.xml
Downloading from Maven central: https://repo1.maven.org/maven2/com/acme/parent/1.0.0-SNAPSHOT/event-processor-1.0.0-SNAPSHOT.pom
Downloading from Confluent: https://packages.confluent.io/maven/com/acme/parent/1.0.0-SNAPSHOT/event-processor-1.0.0-SNAPSHOT.pom
Downloading from Local Maven: file:///home/user/.m2/repository/com/acme/parent/1.0.0-SNAPSHOT/event-processor-1.0.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.324 s
[INFO] Finished at: 2023-01-06T11:54:58+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project app1: Could not resolve
dependencies for project com.acme:app1:jar:1.0.0-SNAPSHOT: Failed to
collect dependencies at com.acme:core:jar:1.0.0-SNAPSHOT: Failed to
read artifact descriptor for com.acme:core:jar:1.0.0-SNAPSHOT: Could
not find artifact com.acme:parent:pom:1.0.0-SNAPSHOT in Maven central
(https://repo1.maven.org/maven2/) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
I've read various docs (https://maven.apache.org/guides/introduction/introduction-to-the-pom.html) and some other questions and answers which seem a little dated.
These all state that if I run something like:
# In root project dir
mvn --projects app1 package --also-make
it correctly builds my single module and also any local dependencies, and it does.
However, I want to be able to use my IDE's (IntelliJ, in this case) Maven support and simply be able to run the module's Maven lifecycle task package from my IDE's Maven tool integration window.
Alternatively, at the very least, I'd like to just be able to go into the child module directory and do a mvn package and have it work. I expect that I can have a team member check out the repository and build a single module that they're working on instead of having to build everything (which may take a long time, especially if a core dependency or parent is changed).
How can I do this? Do I have to build from the parent context (i.e. from the root project dir)? If so, why doesn't Maven just tell me that instead of complaining that it can't find a pom.xml that is quite obviously there (and it knows where it is!)?
I know that dependency resolution is a hard problem, but I'm quite annoyed that such a common functionality such as building a child module is seemingly super hard to do with Maven...

All dependent packages need to be deployed in the local or distant repo before being resolved as dependencies in any of your module.
To deploy a module on which you depend (e.g core module) in the local repo use the mvn install command.
Then the mvn packages command should work in the app1 module.
Furthermore in your case you used
<relativePath/> <!-- lookup parent from repository -->
Which means that to be able to resolve the parent pom from any child module the parent-pom shall also be deployed in a local or distant repository. In your case you also have to mvn install the parent pom.
mvn package does not make your module "visible" to others, it just package everything by default in the target folder of the module. To make it visible locally use mvn install.
Finally for your team to be able to work as you wish you must deploy your jars including the parent pom in a remote / shared jar repository like Nexus for instance.
For that you use the mvn deploy command. But naturally, you need to set up all the deploy configuration and server beforehand... Then it would work as you expect

Related

mvn go-offline trying to download dependencies not in dependency tree

I have a maven build that fails on executing mvn go-offline, because it tries to download log4j-core:2.11.2 - a version which has been removed from my company's Artifactory due to the Log4Shell vulnerability.
But I can't figure out why my project is trying to download that specific version of log4j-core. I have explicitly defined a log4j-core:2.17.1 dependency in my pom, and log4j-core:2.11.2 is nowhere in my project's dependency tree. In addition, running mvn install works fine and doesn't require log4j-core:2.11.2: only the mvn go-offline command thinks it needs 2.11.2.
The project set up with a parent pom, like this:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath/>
</parent>
...
<dependencies>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.1</version>
</dependency>
...
</dependencies>
Result of executing mvn -X dependency:go-offline:
[DEBUG] Resolving artifact org.apache.logging.log4j:log4j-core:pom:2.11.2 from [central (https://artifacts.mycompany.int/artifactory/maven-all, default, releases), snapshots (https://artifacts.mycompany.int/artifactory/maven-all, default, releases+snapshots), apache.snapshots (https://repository.apache.org/snapshots, default, snapshots)]
[INFO] Downloading from central: https://artifacts.mycompany.int/artifactory/maven-all/org/apache/logging/log4j/log4j-core/2.11.2/log4j-core-2.11.2.pom
[DEBUG] Writing tracking file /mybuilddir/.m2/repository/org/apache/logging/log4j/log4j-core/2.11.2/log4j-core-2.11.2.pom.lastUpdated
[WARNING] The POM for org.apache.logging.log4j:log4j-core:jar:2.11.2 is missing, no dependency information available
[DEBUG] Resolving artifact org.apache.logging.log4j:log4j-core:jar:2.11.2 from [central (https://artifacts.mycompany.int/artifactory/maven-all, default, releases), snapshots (https://artifacts.mycompany.int/artifactory/maven-all, default, releases+snapshots)]
[INFO] Downloading from central: https://artifacts.mycompany.int/artifactory/maven-all/org/apache/logging/log4j/log4j-core/2.11.2/log4j-core-2.11.2.jar
[DEBUG] Writing tracking file /mybuilddir/.m2/repository/org/apache/logging/log4j/log4j-core/2.11.2/log4j-core-2.11.2.jar.lastUpdated
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:3.2.0:go-offline (default-cli) on project myproject: org.eclipse.aether.resolution.DependencyResolutionException: Could not find artifact org.apache.logging.log4j:log4j-core:jar:2.11.2 in central (https://artifacts.mycompany.int/artifactory/maven-all) -> [Help 1]
Result of executing mvn -X org.apache.maven.plugins:maven-dependency-plugin:3.3.0:tree -Dverbose=true (the only version of log4j-core that shows up is 2.17.1. Version 2.11.2 is not mentioned anywhere in this tree):
[DEBUG] com.mycompany:myproject:jar:1.7.0
...
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.17.1:compile
...
I cannot understand why my pom is trying to download a dependency version not listed in the tree. Is it some sort of transitive dependency that is not being printed out in the tree? If so, how do I get the dependency tree to print it, as well as which artifact is bringing it in? Does anyone have any advice?
dependency:go-offline try to resolve and download all dependencies used in your project ... but also try to resolve all Maven plugins used in project and their dependencies
Also dependency:tree show what you use in project.
So even if your project have no dependencies to log4j-core:2.11.2 some of plugins used to build project can have it ...
Please examine output of:
mvn dependency:resolve-plugins

Issue in adding third party dependency in Maven during Jenkins build - ODM

I am trying to build ODM projects outside of eclipse using the Jenkins pipeline and Maven plugin. I am following the link : https://www.ibm.com/support/knowledgecenter/en/SSQP76_8.9.0/com.ibm.odm.dserver.rules.designer.run/build_topics/con_buildcmd_intro.html
Though this link works well without the Jenkins pipeline in my local(Windows), but when I try to run the same setup in Jenkins(Linux machine), I am getting the following error :
[WARNING] The POM for com.ibm.rules.buildcommand:rules-compiler-maven-plugin:jar:8.10.0.0 is missing, no dependency information available
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. # helloWorld:hello-xom:[unknown-version], /var/lib/jenkins/workspace/odm-devops-build/Hello XOM/pom.xml, line 19, column 21
[ERROR] Unresolveable build extension: Plugin com.ibm.rules.buildcommand:rules-compiler-maven-plugin:8.10.0.0 or one of its dependencies could not be resolved: Failure to find com.ibm.rules.buildcommand:rules-compiler-maven-plugin:jar:8.10.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced #
[ERROR] Unknown packaging: decisionservice # helloWorld:hello-main:[unknown-version], /var/lib/jenkins/workspace/odm-devops-build/Hello Main Service/pom.xml, line 14, column 16
The pom file which is referred in the above error is as below:
<?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>
<parent>
<groupId>helloWorld</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<relativePath>..</relativePath>
</parent>
<artifactId>hello-main</artifactId>
<packaging>decisionservice</packaging>
<build>
<plugins>
<plugin>
<groupId>com.ibm.rules.buildcommand</groupId>
<artifactId>rules-compiler-maven-plugin</artifactId>
<configuration>
<deployments>
<deployment>
<name>simple dep</name>
</deployment>
</deployments>
<resolvers>
<resolver>
<!-- The values of the kind and url of the project correspond to the 'kind' and 'url' attribute values of an 'entries' element in the .ruleproject file. -->
<kind>JAVA_PROJECT</kind>
<url>platform:/Hello XOM</url>
<!-- The artifactKey references the groupId and artifactId of a Maven dependency. -->
<artifactKey>${project.groupId}:hello-xom</artifactKey>
</resolver>
</resolvers>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hello-xom</artifactId>
<type>jar</type>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Please let me know if anyone has faced a similar issue or has a possible resolution to the above issue.
Thanks in advance.
Possible resolution: "install the Build Command Maven plugin and its related Operational Decision Manager artifacts in your Maven repository" ... "on each machine that contains build agents"
To deploy the Build Command Maven plugin to a remote Maven repository, you must configure Maven in your environment. You then use the following command: mvn deploy:deploy-file -Dfile=rules-compiler-maven-plugin.jar -DpomFile=rules-compiler-maven-plugin.pom
This requires access to the Jenkins / Maven server, and at many companies would be done by DevOps.
You install the Build Command Maven plugin and its related Operational Decision Manager artifacts in your Maven repository.
Deploying the Build Command plugin
You deploy the plugin only once on each machine that contains build agents.
To deploy the Build Command Maven plugin to a remote Maven repository, you must first configure Maven in your environment.
Then, in <InstallDir>/buildcommand/rules-compiler, open a command prompt.
Use the following command:
mvn deploy:deploy-file -Dfile=rules-compiler.jar -DpomFile=rules-compiler-maven-plugin.pom
If you do not have a remote repository, you can test the plugin locally. You run the following command:
mvn install:install-file -Dfile=rules-compiler.jar -DpomFile=rules-compiler-maven-plugin.pom
This command adds the following plugin in your local Maven repository:
com/ibm/rules/buildcommand/rules-compiler
 Deploying the annotations archive
If you want to build COBOL projects or projects that use XOM annotations, you must also deploy the annotations archive to your environment before you can build the projects.
In <InstallDir>/buildcommand/rules-compiler, open a command prompt.
Use the following command:
mvn deploy:deploy-file -Dfile=rules-compiler.jar -DpomFile=xom-annotations.pom
If you do not have a remote repository, you can test the plugin locally. You run the following command:
mvn install:install-file -Dfile=rules-compiler.jar -DpomFile=xom-annotations.pom
This command adds the following plugin in your local Maven repository:
com/ibm/rules/buildcommand/xom-annotation
Source

How do I force Maven to use my local repository rather than going out to remote repos to retrieve artifacts?

I’m using Maven 3.3.3 with Java 8 on Mac Yosemite. I have a multi-module project.
<modules>
<module>first-module</module>
<module>my-module</module>
…
</modules>
When I build my one of my child modules, for example, “my-module” from above, using “mvn clean install”, the build attempts to download the child module artifacts from a remote repository I have defined in my ~/.m2/settings.xml file. Output is below
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-module 87.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloaded: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml (788 B at 0.9 KB/sec)
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-20151104.200545-4.pom
How do I force Maven to check my local ~/.m2/repository first before trying to download from the remote repositories? Below is where I have my remote repositories defined in my ~/.m2/settings.xml file …
<profile>
<id>releases</id>
<activation>
<property>
<name>!releases.off</name>
</property>
</activation>
<repositories>
<repository>
<id>releases</id>
<url>https://my.remoterepository.com/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>snapshots</id>
<activation>
<property>
<name>!snapshots.off</name>
</property>
</activation>
<repositories>
<repository>
<id>snapshots</id>
<url>https://my.remoterepository.com/nexus/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
Edit: In response to the answer saying that the download occurs when the artifact is not there, below is the terminal output in which I prove the file was there in my repo but Maven is trying to download it anyway ...
Daves-MacBook-Pro-2:my-module davea$ ls -al ~/.m2/repository/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-SNAPSHOT.jar
-rw-r--r-- 1 davea staff 10171 Nov 5 10:22 /Users/davea/.m2/repository/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-SNAPSHOT.jar
Daves-MacBook-Pro-2:my-module davea$ mvn clean install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.mainco.subco:my-module:jar:87.0.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-antrun-plugin # org.mainco.subco:my-module:[unknown-version], /Users/davea/Documents/sb_workspace/my-module/pom.xml, line 678, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-module 87.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloaded: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml (788 B at 0.8 KB/sec)
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-20151106.043202-8.pom
Downloaded: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first- module-87.0.0-20151106.043202-8.pom (3 KB at 21.9 KB/sec)
Downloading: http://download.java.net/maven/2/org/mainco/subco/subco/87.0.0-SNAPSHOT/maven-metadata.xml
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/subco/87.0.0-SNAPSHOT/maven-metadata.xml
The dependency has a snapshot version. For snapshots, Maven will check the local repository and if the artifact found in the local repository is too old, it will attempt to find an updated one in the remote repositories. That is probably what you are seeing.
Note that this behavior is controlled by the updatePolicy directive in the repository configuration (which is daily by default for snapshot repositories).
Use mvn --help and you can see the options list.
There is an option like -nsu,--no-snapshot-updates Suppress SNAPSHOT updates
So use command mvn install -nsu can force compile with local repository.
To truly force maven to only use your local repo, you can run with mvn <goals> -o. The -o tells maven to let you work "offline", and it will stay off the network.
Follow below steps:
Ensure to delete all the contents of the jar folder located in your local except the jar that you want to keep.
For example files like .repositories, .pom, .sha1, .lastUpdated etc.
Execute mvn clean install -o command
This will help to use local repository jar files rather than connecting to any repository.
Maven always checks your local repository first, however,your dependency needs to be installed in your repo for maven to find it.
Run mvn install in your dependency module first, and then build your dependent module.
In my case I had a multi module project just like you. I had to change a group Id of one of the external libraries my project was depending on as shown below.
From:
<dependencyManagement>
<dependency>
<groupId>org.thirdparty</groupId>
<artifactId>calculation-api</artifactId>
<version>2.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependencyManagement>
To:
<dependencyManagement>
<dependency>
<groupId>org.thirdparty.module</groupId>
<artifactId>calculation-api</artifactId>
<version>2.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependencyManagement>
Pay attention to the <groupId> section. It turned out that I was forgetting to modifiy the corresponding section of the submodules that define this dependency in their pom files.
It drove me very crazy because the module was available locally.
Even when considering all answers above you might still run into issues that will terminate your maven offline build with an error. Especially, you may experience a warning as follwos:
[WARNING] The POM for org.apache.maven.plugins:maven-resources-plugin:jar:2.6 is missing, no dependency information available
The warning will be immediately followed by further errors and maven will terminate.
For us the safest way to build offline with a maven offline cache created following the hints above is to use following maven offline parameters:
mvn -o -llr -Dmaven.repo.local=<path_to_your_offline_cache> ...
Especially, option -llr prevents you from having to tune your local cache as proposed in answer #4.
Also take care that parameter <localRepositoryin> in your settings.xml points to the correct folder of your local Maven repository.
The -o option didn't work for me because the artifact is still in development and not yet uploaded and maven (3.5.x) still tries to download it from the remote repository because it's the first time, according to the error I get.
However this fixed it for me: https://maven.apache.org/general.html#importing-jars
After this manual install there's no need to use the offline option either.
UPDATE
I've just rebuilt the dependency and I had to re-import it: the regular mvn clean install was not sufficient for me
I had the exact same problem. Running mvn clean install instead of mvn clean compile resolved it.
The difference only occurs when using multi-maven-project since the project dependencies are uploaded to the local repository by using install.
use <classpathentry kind="var" path="M2_REPO/your jar location
without creating any environment veriable
just to give my 2 cents. For me, it was only necessary to find the jar inside the ~/.m2/repository directory and use its version. So, after using
cd local-dependency/
mvn install
the local-dependency jar will be in the .m2/repository/com/your-organization/local-dependency/
~$ tree ~/.m2/repository/com/your-organization/local-dependency/
/home/felipe/.m2/repository/com/your-organization/local-dependency/
├── 0.1-SNAPSHOT
│   ├── maven-metadata-local.xml
│   ├── _remote.repositories
│   ├── local-dependency-0.1-SNAPSHOT.jar
│   ├── local-dependency-0.1-SNAPSHOT.pom
│   └── resolver-status.properties
└── maven-metadata-local.xml
then use it as a local dependency
<dependency>
<groupId>com.your-organization</groupId>
<artifactId>local-dependency</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>

Why does "mvn dependency:tree" list one version, but "mvn clean install" try to download another version?

I've got a Maven (3.2.5) project which is failing due to a missing dependency. The relevant part of the mvn clean install output:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single (package-jar-with-dependencies) on project splitter: Failed to create assembly: Failed to resolve dependencies for project: groupId1:splitter:jar:2.12.3: Missing:
[ERROR] ----------
[ERROR] 1) groupId2:location-service:jar:2.12.3
However, mvn depdency:tree claims that the 2.12.3 version is not necessary:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # splitter ---
[INFO] groupId1:splitter:jar:2.12.3
[INFO] +- groupId2:location-service:jar:2.12.1:compile
There is no other location-service dependency listed.
The pom.xml explicitly calls out the 2.12.1 dependency:
<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>
<parent>
<groupId>groupId2</groupId>
<artifactId>artifactId</artifactId>
<version>2.12.0</version>
</parent>
...
<groupId>groupId1</groupId>
<artifactId>splitter</artifactId>
<packaging>jar</packaging>
<version>2.12.3</version>
<name>splitter</name>
<url>http://maven.apache.org</url>
...
<dependencies>
<dependency>
<groupId>groupId2</groupId>
<artifactId>location-service</artifactId>
<version>2.12.1</version>
</dependency>
...
Interestingly, the parent pom.xml is not available in this directory structure (the person that created the SVN branch branched a portion of the repository that didn't include the parent pom.xml). However, Maven does not complain about it missing, so it's getting it from my~/.m2/repository directory.
Sorry reputation seekers, yet again I found the solution to my question while composing it. But it's complicated enough to go ahead and post the question and answer, in case anyone else runs into a similar problem.
The problem turned out to be that the parent pom.xml in my ~/.m2/repository directory set the location-service dependency to ${project.version}. Apparently this was enough for the maven-assembly-plugin to want to download it, despite the explicit dependency in the module pom.xml. This is a bug in maven-assembly-plugin:2.2-beta-5. Neither the module nor the parent pom.xml name an explicit version of the maven-assembly-plugin. I haven't the foggiest idea why maven is selecting the 2.2-beta-5 version to download, as it isn't even close to the latest version. mvn dependency:tree -Dverbose doesn't even mention maven-assembly-plugin. Explicitly using maven-assembly-plugin:2.5.5 solves the problem.

Setup Maven to use our dedicated server

We would like to maintain our own repository server that is totally cut-off from the Internet because of our company policies.
To achieve this, we install Maven in our system and executed the following command to force Maven to download all the dependencies for offline purpose:
mvn dependency:go-offline
Upon completion, we move all the downloaded dependencies into our Tomcat server and update maven's settings.xml to mirror to a URL served by Tomcat (where all the dependencies are stored). We are not using 3rd party repository manager for now.
<mirror>
<id>ProjectsCentralRepository</id>
<mirrorOf>*</mirrorOf>
<name>Central Repository</name>
<url>http://localhost:8080/repos</url>
</mirror>
Problem occurs when we remove all the dependencies in our .m2\repository and try to run "mvn package" to package a simple project that does not have any dependencies (refers to our pom.xml). Many of the dependencies were downloaded successfully from our server but we do not understand why the following error occurs. Weren't all the dependencies downloaded already when we execute mvn dependency:go-offline?
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources) on project test: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:2.6:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or on
e of its dependencies could not be resolved: The following artifacts could not be resolved: org.apache.maven:maven-profile:jar:2.0.6, org.apache.maven:maven-repository-metadata:jar:2.0.6, org.apache.maven:maven-plugin-registry:jar:2.0.6, classworlds:classworlds:jar:1.1-alpha-2: Could not find artifa
ct org.apache.maven:maven-profile:jar:2.0.6 in ProjectsCentralRepository (http://localhost:8080/repos) -> [Help 1]
[ERROR]
I also notice Maven had downloaded multiple versions of different dependencies. For example, it had downloaded 2.05 to 2.2.0 of the maven-profile POM files but only 2.0.9 has the jar file. How do I force maven to download only the latest version of Maven dependencies and to use the latest version when performing "mvn package" goal?
Thank you guys.
Our pom.xml:
<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>xx.yyyy.Test</groupId>
<artifactId>test</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>Testing</name>
<url>http://maven.apache.org</url>
</project>

Resources