Maven子模块依赖性未显示

时间:2019-03-28 15:01:29

标签: java maven spring-boot

我必须向现有的Spring Boot项目之一添加新功能。我决定在项目内创建一个模块(因为将来从技术上讲该模块将可以被其他项目重用)。所以我的项目结构如下:

ParentProject
|----myModule
|    |----src/ // all module code in here
|    |----pom.xml
|----src/ //all parent project code in here
|----pom.xml

现在,我有一个要添加到子模块的依赖项。但是,当我将其添加到子模块的pom时,它们实际上并未显示。

这是我的孩子pom.xml

<parent>
    <artifactId>parent-artifact-id</artifactId>
    <groupId>parent.group.id</groupId>
    <version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>mysubmodule</artifactId>

<repositories>
    <repository>
        <id>lightstreamer</id>
        <url>https://www.lightstreamer.com/repo/maven/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.lightstreamer</groupId>
        <artifactId>ls-javase-client</artifactId>
        <version>4.3.0</version>
    </dependency>
</dependencies>

我可以将这种依赖关系真正显示在项目中的唯一方法是将其放在父级pom.xml中。如果我将它放在子pom中,它会“找到”它,但实际上不会将其添加到我的外部库中。

还要注意,我的ParentProject pom本身也有一个<parent>标签,因为这是一个Spring Boot项目,不确定是否会更改任何内容。

关于父母/子女关系,我是否缺少某些东西?我是否必须将所有依赖项都放在<dependencyManagement>下的父级中?

我想以某种方式使子模块保持“解耦”状态。意味着可以将其添加到需要它的任何其他项目中。怎么办呢?

谢谢

编辑: 这是我的父母pom.xml

<?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>
<packaging>pom</packaging>
<modules>
    <module>myModule</module>
</modules>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.2.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<groupId>parent.group.id</groupId>
<artifactId>parent-artifact-id</artifactId>
<version>1.0.0</version>
<name>myName</name>
<description>my description</description>

<properties>
    <java.version>1.8</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-integration</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <!-- etc -->
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

编辑2:

如果将依赖项放入子pom中,则无法导入该软件包。但是,我所做的奇怪的是,我将依赖项放入了父pom中,并试图导入该包。它没有用,但是IntelliJ确实为我提供了“将com.lightstreamer ...添加到类路径”的选项。我这样做了,现在无论依赖项是在父还是子pom中,我都可以导入该包。因此,从技术上讲,它现在可以工作。但是我不确定为什么在不必与其他任何库一起执行时,必须告诉IntelliJ将其添加到类路径中,我认为这是Maven所做的。

0 个答案:

没有答案