Let's assume that our build is about building modules from A to Z. All the version elements in pom files for these projects are set to -SNAPSHOT.
When we build the pom file, maven starts with project A, then goes to B, and then finally reaches the project Z. If Z depends on A, does maven check the remote repo for a latest A-SNAPSHOT.jar and potentially replace A-SNAPSHOT.jar that just got created as part of the same build at A/target/ and/or local Maven repo?
I think -o
can avoid above scenario but I just wanted to understand.
Is it possible to set -o
to a specific groupId to avoid obscure errors that might happen in above scenario.
Is it possible to configure the build in such a way to download any artifacts unavailable in the local repo but don't replace existing ones.
No, projects in the reactor will always be preferred over other dependencies.
This hold true even regardless of the following circumstances:
-U
flag set, meaning that update checks are forced.<updatePolicy>
to always
in either settings.xml
or in the POM.install
plugin to <installAtEnd>true</installAtEnd>
Maven will figure out which artifacts are part of your reactor and exclude them from update checks.
This is quite easy to prove. If you try running Maven with either of the configurations above, you will see that Maven won't download artifact A
(for instance), since each download is logged in the console.
For example, let's assume that you have this root POM:
<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>org.example</groupId>
<artifactId>root</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>root</name>
<modules>
<module>A</module>
<module>B</module>
...
<module>Z</module>
</modules>
</project>
And each module looks like this:
<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>
<parent>
<groupId>org.example</groupId>
<artifactId>root</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<name>...</name>
<artifactId>...</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>
but the last one looks like this:
<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>
<parent>
<groupId>org.example</groupId>
<artifactId>root</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>Z</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Z</name>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>A</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Then no, module A will never be replaced by another version of the artifact from the repository.