Maven打包jar多模块项目

Maven package jar multi-module project

我有一个多模块项目。我想从这个模块之一制作一个可执行的 jar。根 pom 是

    <groupId>ru.netCracker</groupId>
    <artifactId>root</artifactId>
    <!--todo:Version-->
    <version>1.1.0</version>
    <packaging>pom</packaging>

    <properties>...</properties>

    <modules>
        <module>client</module>
        <module>serverRoot</module>
    </modules>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin> 
        </plugins>
    </build>
</project>

在子pom中指定了jar打包设置和一些依赖。

    <artifactId>client</artifactId>
    <!--todo:Version-->
    <version>1.1.0</version>

    <parent>
        <groupId>ru.netCracker</groupId>
        <artifactId>root</artifactId>
        <version>1.1.0</version>
    </parent>

    <properties>
        <maven.jar.version>3.0.2</maven.jar.version>
        <jfoenix.version>1.11.1</jfoenix.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>ru.netCracker</groupId>
            <artifactId>root</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>${maven.jar.version}</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>sample.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

但是 Maven 编译器说:

[ERROR] Failed to execute goal on project client: Could not resolve dependencies for project ru.netCracker:client:jar:1.1.0: Failure to find ru.netCracker:root:jar:1.1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

我必须向 maven 写入什么命令来打包这个 jar?

Maven 只是抱怨它无法找到 root 模块的依赖项,因为它尚未构建。

我建议进行以下更改 -

  1. client 模块中的 parent 标签更改为

    <parent>
        <groupId>ru.netCracker</groupId>
        <artifactId>root</artifactId>
        <version>1.1.0</version>
        <relativePath>../</relativePath>
    </parent>
    
  2. 删除以下代码,因为您有 root 作为您的 parent。

    <dependencies>
        <dependency>
            <groupId>ru.netCracker</groupId>
            <artifactId>root</artifactId>
            <version>1.1.0</version>
        </dependency>
    </dependencies>