简体   繁体   中英

How to not pull module (dependency) from settings.xml servers?

I have the following project package structure.

parent
|- module1
|- module2    
|- module3

I am able to include module3 as a dependency in both pom.xml files of module1 & module2. This gives me access to all of the dependencies & code from module3.

<dependency>
    <groupId>my.group</groupId>
    <artifactId>module3</artifactId>
    <version>1.0.0</version>
</dependency>

However, when I run maven commands such as dependency:tree on the pom file of module1 or module2, maven will try to search on certain <servers> that are listed in my settings.xml file in order to try & download module3 as an artifact. module3 is not deployed to any <server> at the moment so, the maven command fails with following error

[ERROR] Failed to execute goal on project module1: Could not resolve dependencies for project my.group:module1:jar:1.0.0-SNAPSHOT: Failed to collect dependencies at my.group:module3:jar:1.0.0-SNAPSHOT: Failed to read artifact descriptor for my.group:module3:jar:1.0.0-SNAPSHOT: Could not transfer artifact my.group:module3:jar:1.0.0-SNAPSHOT from/to MyServer (https://example): Access Denied to: .......etc.

Ideally, module3 would not be deployed at all as an artifact but, instead it might simply have <packaging>pom</packaging> . module3 is just some module that should only be used by module1 & module2. Also, FYI the dependency tree of module3 builds perfectly fine.

  1. Dependencies should never be of packaging pom . The need to be proper JARs and also need to be deployed to the repository.

  2. Usually, you run build commands on the parent of the multi module project. If you want to restrict the build to one module, use -pl .

  • Make sure the version of the module is correct.

Normally, when you run "mvn clean install" in parent project, all modules will be built, Order builds module3 -> module1 and module2. module3 is always built first.

Thanks

As far as I understand the question, the following maven module are part of the same reactor:

parent
|- module1
|- module2    
|- module3

parent should have:

<modules>
  <module>module1</module>
  <module>module2</module>
  <module>module3</module>
</modules>

Otherwise, Maven will not look in the file system but in the local repository.

Also, to my understanding, in your example module1 and module2 are two jar packaged module (eg: <packaging>jar</packaging> or omitted) but parent and module3 are two pom packaged module (eg: <packaging>pom</packaging> ).

I suppose you want to create some kind of module importing only dependencies without code, in which case you should import it using:

<dependency>
    <groupId>my.group</groupId>
    <artifactId>module3</artifactId>
    <version>1.0.0</version>
    <type>pom</type>
</dependency>

Strange as it may be, this should work.

You can also use --offline to force maven to not go online.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM