Search code examples
mavenmaven-3

Prevent Maven from downloading own project modules as artifacts from remote repo


There is a maven project with several modules. All modules have the same version 1.2.0-SNAPSHOT.

While building the project specifying a module name in the CLI parameters (e.g. running some tests for a module) I see warnings in the log for each module

Command

mvn verify -pl module-with-integr-tests -D it.test=MyIntegrationTest

Part of the log

[WARNING] The POM for com.some:my-module-a:jar:1.2.0-SNAPSHOT is missing,
          no dependency information available
Downloading from central:
  https://common.repositories.some.com:443/build-releases/com/some/my-module-a/1.2.0-SNAPSHOT/maven-metadata.xml
Downloading from snapshots:
  https://common.repositories.some.com:443/build-snapshots/com/some/my-module-a/1.2.0-SNAPSHOT/maven-metadata.xml

I would like to avoid these attempts to download artifacts for own project modules, because most of them are not artifacts being deployed and never appear in the artifactory. Instead these modules are supposed to be built locally and used as dependencies by other modules of the same project.

How to prevent Maven from downloading own project modules?


Solution

  • With Maven 3, you must mvn install the dependencies.

    However, your command —

    mvn verify -pl module-with-integr-tests -D it.test=MyIntegrationTest
    

    — should work in Maven 4, although it is of course subject to change at the moment since they do not yet have a final release. I have tested it myself with 4.0.0-alpha-8 and 4.0.0-alpha-12 on a private project and it works well. You should see a log like this indicating that Maven is putting the artifact in a place within the project structure (i.e., not in ~/.m2/repository) to find later:

    [INFO] Copying com.example:example-lib:pom:1.0-SNAPSHOT to project local repository
    [INFO] Copying com.example:example-lib:jar:1.0-SNAPSHOT to project local repository
    

    For more detail, see What's New in Maven 4: Root-reactor aware subfolder builds. It only mentions mvn -f submodule/pom.xml plugin:goal and cd submodule && mvn plugin:goal, but as mentioned I verified that mvn -pl submodule plugin:goal works as well. mvn -pl submodule1,submodule2 plugin:goal (etc.) also works!