简体   繁体   English

如何解决这个 maven 多模块依赖问题? 安装后不是从本地m2导入

[英]How to solve this maven multi module dependency issue? It's not importing from local m2 after installing

I have a project with two modules in that.我有一个包含两个模块的项目。 The parent POM looks like this:父 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>org.example</groupId>
    <artifactId>bc</artifactId>
    <packaging>pom</packaging>
    <version>1.3-SNAPSHOT</version>

    <modules>
        <module>njoy</module>
        <module>api</module>
    </modules>

</project>

The njoy module POM looks like this: njoy模块 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>bc</artifactId>
        <groupId>org.example</groupId>
        <version>1.3-SNAPSHOT</version>
    </parent>


    <modelVersion>4.0.0</modelVersion>

    <artifactId>njoy</artifactId>
    <packaging>jar</packaging>

</project>

The api module POM looks like this: api模块 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>bc</artifactId>
        <groupId>org.example</groupId>
        <version>1.3-SNAPSHOT</version>
    </parent>


    <modelVersion>4.0.0</modelVersion>

    <artifactId>api</artifactId>
    <packaging>jar</packaging>

</project>

I have done mvn clean install for the parent POM so that it gets into my local m2 repository.我已经为父 POM 完成了mvn clean install ,以便它进入我的本地 m2 存储库。 Now i want to use this project as a dependency in another project(say experiments) by providing it as dependency.现在我想通过提供它作为依赖项来将此项目用作另一个项目(例如实验)中的依赖项。 These are the folders created in my m2 repo.这些是在我的 m2 存储库中创建的文件夹。

在此处输入图片说明

This is my other project where i am using it as a dependency, and the POM for it looks like this:这是我使用它作为依赖项的另一个项目,它的 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>org.example</groupId>
    <artifactId>experiments</artifactId>
    <version>1.0-SNAPSHOT</version>


    <dependencies>
        <dependency>
            <groupId>org.example</groupId>
            <artifactId>bc</artifactId>
            <version>1.3-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.example</groupId>
            <artifactId>klk</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>

</project>

But it cannot find the multi-module project artifact, where there is another dependency which is a single module project( klk ) and there is no issue.但是它找不到多模块项目工件,其中还有另一个依赖项是单模块项目( klk )并且没有问题。

在此处输入图片说明

Please help.请帮忙。 What am i missing here?我在这里缺少什么?

Thanks in advance!!提前致谢!!

The artifact bc is just a pom with some modules.神器bc只是一个带有一些模块的 pom。 It cannot be used as a dependency.它不能用作依赖项。 You probably thought you can reference "all artifacts" by referencing the parent POM.您可能认为可以通过引用父 POM 来引用“所有工件”。 This is not possible.这不可能。

The artifacts njoy and api are jars -- they can be used as a dependency of another project.工件njoyapinjoy它们可以用作另一个项目的依赖项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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