带有Maven多模块的Spring Boot无法正常运行

时间:2019-01-30 19:33:48

标签: java git maven spring-boot

我正在尝试创建将容纳所有子弹簧启动模块的父pom,但是当我构建父pom时,出现以下错误。

[错误]项目com.some.special:special-parent:0.0.1(C:\ Users \ location \ git \ special-parent-pom \ pom.xml)有1个错误 [错误]子模块C:\ Users \ location \ git \ special-parent-pom .. \ C:\ Users \ location \ git \ special-parent-pom \ pom.xml的特殊安全性不存在。 strong>

下面是我的项目结构:

-special-parent-pom

-特殊安全性

父级和子级都在同一文件夹中(C:\ Users \ location \ git)

下面是父pom.xml:

<modelVersion>4.0.0</modelVersion>

    <groupId>com.some.special</groupId>
    <artifactId>special-parent</artifactId>
    <version>0.0.1</version>
    <packaging>pom</packaging>

    <name>special-parent</name>
    <description>special-parent</description>
    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.2.RELEASE</version>
    </parent>


        <modules>
            <module>../special-security</module>
         </modules>

下面是子pom.xml:

<modelVersion>4.0.0</modelVersion>
    <artifactId>special-security</artifactId>
    <packaging>jar</packaging>

    <parent>
        <groupId>com.some.special</groupId>
        <artifactId>special-parent</artifactId>
        <version>0.0.1</version>
        <relativePath>../special-parent/pom.xml</relativePath>
    </parent>

我无法确定错误的出在哪里,有人可以帮我解决这个问题还是分享任何例子。我的最终目标是当我构建父pom时,应该使用jar构建所有子模块,基本上是spring boot child模块。

1 个答案:

答案 0 :(得分:0)

这是编译工件并使用repackage spring-boot-maven-plugin进行编译的最小示例。给出以下目录清单:

Project
├── pom.xml
└── special-security
    ├── pom.xml
    └── src
        └── main
            ├── java
            │   └── com
            │       └── some
            │           └── special
            │               └── SpecialSecurity.java
            └── resources
                └── META-INF
                    └── MANIFEST.MF

父母 pom.xml内容:

Project
├── 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>

    <groupId>com.some.special</groupId>
    <artifactId>special-parent</artifactId>
    <version>${revision}</version>
    <name>special-parent</name>
    <packaging>pom</packaging>

    <properties>
        <revision>0.0.1</revision>
    </properties>

    <modules>
        <module>special-security</module>
    </modules>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.1.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

孩子 pom.xml内容:

Project
├── ...
└── special-security
    ├── pom.xml
    ...
<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>

    <artifactId>special-security</artifactId>
    <packaging>jar</packaging>
    <name>special-security</name>

    <parent>
        <groupId>com.some.special</groupId>
        <artifactId>special-parent</artifactId>
        <version>${revision}</version>
    </parent>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.2.RELEASE</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <finalName>special-security</finalName>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

您可以使用package mvn package来构建工件,或者使用.m2将其安装到本地mvn install中。

注意:使用revision属性至少需要maven 3.5.0-beta-1指向:https://maven.apache.org/maven-ci-friendly.html。在撰写本文时,本示例中使用的插件的版本是https://mvnrepository.com/上的最新版本。示例使用的源代码./special-security/src/main/java/com/some/special/SpecialSecurity.java

package com.some.special;

public class SpecialSecurity {

    public static void main(String[] args) {
        System.out.print("Hello World\n");
    }
}